0
爲什麼我在控制器中定義'sayHi',並且它不顯示在模板中?爲什麼指令控制器中定義的變量不起作用?
JS:
(function(){
var app = angular.module('myApp', []);
app.directive("directive1", function(){
return {
restrict : 'E',
scope: {
},
link : function($scope){
},
controller: ['$scope', function($scope){
$scope.sayHi = 'hi';
window.console.log($scope.sayHi);
}]
};
});
})();
HTML:
<div style="border: 1px solid; padding: 10px; min-height: 100px;">
Directive1 :
<directive1>
{{sayHi}}
</directive1>
</div>
該控制器與您的第一個指令有關,而不是第二個 –