angular.js - angularjs中自定义指令scope的问题
淡淡烟草味
淡淡烟草味 2017-05-15 17:07:33
0
4
702

angularjs中自定义的指令中scope的值为{}创造了一个隔离作用域,但依然能访问到父级作用域中的属性,怎么回事?(隔离作用域应该不能访问父级作用域的属性啊,在没有进行绑定策略之前)

淡淡烟草味
淡淡烟草味

reply all (4)
巴扎黑

First of all, you didn’t assign a value to the scope attribute in your example. The scope attribute has three values: true, false, {}. false is the default value.

Default, false. At this time, the child scope and the parent scope are one, and the value of scope.$$id is the same.

When

is true, a new scope is created, and the scope.$$id value is different. However, this scope inherits from the parent scope. It is the same as the characteristics of the native js scope chain. The child scope can access the properties and methods in the parent scope, but the parent scope cannot access the properties and methods of the child scope.

When

is {}, it is real isolation. At this time, the scope of the custom directive has nothing to do with the parent scope. But what if you still want to access the property methods of the parent scope? Just configure the corresponding properties in {}. Please refer to Google Baidu for the specific configuration method.

    Peter_Zhu

    You can access it in the same controller, but you can’t access it in different controllers

      左手右手慢动作

      You are not in quarantine. If you are in quarantine, add scope:{}

        phpcn_u1582

        There are two ways to isolate a scope:

        scope: true scope: {}
          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!