当我给我的指令指定一个独立的作用域时,用“scope:{}”替换“scope:false”,我需要做些什么来使scope.test在我的HTML中可见?
我的指令:
angular
.module("MyApp", [])
.directive("myDir",() => {
return {
scope: false,
restrict: "A",
link: (scope, element) => {
scope.test = 'my test';
}
};
});
我的HTML:
<div ng-app="MyApp">
<div my-dir>{{test}}</div>
</div>
没有控制器,只在我向链路功能。
似乎是为我工作,见[这里](http://plnkr.co/edit/Lkx1RLf5neaLG0IaWAgm?p=preview),即使在[codepen(https://codepen.io/_miki_/pen/RLMKKV) –
谢谢Pankaj。让我澄清一下;我的codepen与“scope:false”一起工作,但是当我给这个指令一个新的作用域时,设置“scope:{}”作用域变量在HTML中不再可见。 – Miki
使用独立作用域的唯一方法是使用$ parent ref:'scope。$ parent.test ='my test';' – dfsq