<div ng-init="siblingProperty='moredata'">
Inside Div Two: {{ aThirdProperty }}
<div ng-init="aThirdProperty = 'data for 3rd property'" ng-controller="SomeController">
Inside Div Three: {{ aThirdProperty }}
<div ng-controller="SecondController">
Inside Div Four: {{ aThirdProperty }}
<br>
Outside myDirective: {{ myProperty }}
<div my-directive ng-init="myProperty = 'wow, this is cool'" >
Inside myDirective: {{ myProperty }}
<div>
</div>
</div>
</div>
<script>
angular.module('myApp', [])
.controller("SomeController",function(){
})
.controller("SecondController",function(){
})
.directive('myDirective', function() {
return {
restrict: 'A',
scope: {}
};
});
</script>
我的理解是:
ng-init="myProperty = 'wow, this is cool'"初始化内部作用域值。
scope为false时,指令和父级作用域共同使用一个作用域,所以Outside myDirective有值;
scope为true时,指令继承父级作用域并创建一个新作用域,所以初始化后,Outside myDirective在外部不能取到这个新创建作用域的值;
问题来了,scope为{}时,不是生成的隔离作用域吗,为什么外面Outside myDirective有值呢??