问题
Why i defined 'sayHi' in the controller, and it does not display in the template?
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>
detail plnkr
回答1:
Your directive doesn't have any template. You need to add
template: '{{ sayHi }}',
To your directive definition. The content inside the <directive1></directive>
does not constitute the template of the directive.
来源:https://stackoverflow.com/questions/34893982/why-variable-defined-in-the-directive-controller-not-working