I am encountering an issue with two directives on the same page. The first directive is functioning correctly, but the second one is not working as expected.
Below is the code snippet:
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();
});
}
}
})
However, the second directive does not seem to be displaying. Can someone please point out what I might be doing wrong?
Apologies for my oversight. I realize now that I forgot to include the copy-pasted directives. Everything should be in order now.