我想從一個孤立的指令內更改一個$ scope變量,這怎麼可能?
我已經嘗試在指令作用域中使用'@,=,&'語法,但無法使其正常工作。
這是我的簡化代碼
JS
app.controller('testCtrl', function($scope) {
$scope.hello = 'hello';
}
app.directive('testDirective', function() {
return {
restrict: 'E',
template: '<div>{{text}}</div>',
scope: {},
link: function(scope, element) {
scope.text = 'this is my text';
scope.hello = 'hello world!';
}
};
});
HTML
<body>
{{ hello }}
<test-directive />
</body>
這是輸出我想
hello world!
this is my text
很好的解決方案,謝謝! – Inzajt 2015-01-04 10:53:48