[英]Angular 2nd directive not working
I have 2 directives in one page. 我在一页中有2条指令。 The first one works fine, but the second one not working.
第一个工作正常,但第二个工作不正常。
This is my Code: 这是我的代码:
HTML 的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 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();
});
}
}
})
But The second Directive never show. 但是第二指令从不显示。 What I am doing wrong?
我做错了什么?
Sorry for my mistake. 对不起,我错了。 I forget to copy paste the directives.
我忘了复制粘贴指令。 I think now is ok
我想现在还可以
Remove the following line in your second directive:- 在第二个指令中删除以下行:
replace:true ,
The reason with the explanation is already available. 带有说明的原因已经存在。 Refer this link Explain replace=true in Angular Directives (Deprecated)
请参考此链接Angular Directives中的Explain replace = true(已弃用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.