我想从一个孤立的指令内更改一个$ 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