开发者社区 问答 正文

关于ng指令隔离作用域的问题

<body ng-app="myApp">
<div ng-controller="MainController">
 Outside myDirective:{{myProperty}}
 <div my-directive ng-init="myProperty='wow,this is coll'">
     Inside myDirective:{{myProperty}}
 </div>
</div>

这是html的文件
下边是js的
1 scope=true

 .directive('myDirective',function () {
            return {
                restrict:'A',
                //scope:{},
                scope:true,
                priority:100,
                template:'<div>Inside myDirective {{myProperty}}</div>'
            };
        });

ff下显示
Outside myDirective:
Inside myDirective wow,this is coll

2 scope {}

.directive('myDirective',function () {
            return {
                restrict:'A',
                scope:{},
                priority:100,
                template:'<div>Inside myDirective {{myProperty}}</div>'
            };
        });

ff 下显示

Outside myDirective:wow,this is coll
Inside myDirective 

scope:true; 将会创建一个新的作用域出来,所以本级可以读到myPropery上一级读取不到
scope:{},为甚么上一级可以读到!本级读取不到呢?

这个实在能晕了!不懂啊!请各位指点!谢谢

展开
收起
杨冬芳 2016-06-17 18:03:15 2109 分享 版权
1 条回答
写回答
取消 提交回答
问答分类:
问答地址: