Ich habe 2 Direktiven auf einer Seite. Der erste funktioniert gut, aber der zweite funktioniert nicht.Angular 2. Direktive funktioniert nicht
Das ist mein Code:
HTML
<body class="login" ng-app="Login">
<div ng-controller="HttpLoginController">
<wrongdetails></wrongdetails>
<loading></loading>
<input type="submit" ng-click="LoginUser()" value="Login" />
</div>
</body>
JS
var app = angular.module("Login", [])
app.controller("HttpLoginController", function($scope,$http){
$scope.LoginUser = function(){
$scope.loading = true;
var data = [];
var config = {}
$http.post('Mylink', data, config)
.success(function (data, status, headers, config) { $scope.loading = false;})
.error(function (data, status, header, config) {$scope.wrongdetails = true; });
};
});
//Directives
app.directive('loading', function() {
return {
restrict: 'E',
//replace:true,
template: '<div id="loading"> <div class="progress-line"></div><br/> </div>',
link: function (scope, element, attr) {
scope.$watch('loading', function (val) {
if (val)
$(element).show();
else
$(element).hide();
});
}
}
})
app.directive('wrongdetails', function() {
return {
restrict: 'E',
replace:true,
template: '<div class="alert alert-danger display-hide"><button class="close" data-close="alert"></button><span> Error. </span></div>',
link: function (scope, element, attr) {
scope.$watch('wrongdetails', function (val) {
if (val)
$(element).show();
else
$(element).hide();
});
}
}
})
aber die zweite Richtlinie niemals zeigen. Was mache ich falsch?
Entschuldigung für meinen Fehler. Ich vergesse das Kopieren der Direktiven. Ich denke, jetzt ist ok
Sie sollten den Code für beide Direktiven (falls vorhanden) angeben. Sonst ist deine Frage nicht wirklich komplett ... – Ivica
Sorry, ich vergesse das Kopieren der Direktiven. – Dimitris