我有一個問題,在HTML頁面上顯示和隱藏div模板。這裏是一個簡單的JSFiddle示例Example。ngShow無法從HTML上的模板工作
app.directive('example', function() {
return {
restrict: 'E',
template: '<button ng-click=\"clickMe()\">Click me</button>',
scope: {
exampleAttr: '@'
},
link: function (scope) {
scope.clickMe = function() {
scope.showMe = !scope.showMe;
};
}
};
});
和HTML是這樣的:
<body ng-app="demo" ng-controller="exampleController">
<div>
<div ng-controller="exampleController as ctrl">
<example example-attr="xxx">
<p ng-show="showMe">Text to show</p>
</example>
</div>
</div>
我不能在這個example添加我的HTML代碼模板一樣,因爲我的div我要顯示或隱藏是一個整個html頁面。
app.directive('example', function() {
return {
restrict: 'E',
template: '<p ng-show=\"showMe\">Text to show</p><button ng-click=\"clickMe()\">Click me</button>',
scope: {
exampleAttr: '@'
},
link: function (scope) {
scope.clickMe = function() {
scope.showMe = !scope.showMe;
};
}
};
});
在此先感謝
感謝男人,它的工作,我想要的 – Ayyoub
並且非常感謝解釋和評論 – Ayyoub
沒問題,很高興幫助@Ayyoub –