search

Home  >  Q&A  >  body text

angular.js - angular directive problem?

For scope, when should you use an independent scope and when should you inherit the scope of the parent class? Are there any application scenarios?

滿天的星座滿天的星座2774 days ago570

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 16:55:29

    Normally, it is not recommended to rely on the inheritance relationship of the scope to transfer data. Data can be transferred through angular's pub/sub, or data between different scopes can be shared through service. The directive will generate an independent scope only after you specify the scope parameter. The independent scope is for interface isolation and only provides limited external access rights, so that the component can be reused in different environments to implement web components.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:55:29

    Independent components use independent scopes. I feel that in accordance with the componentization concept and performance tuning considerations, independent scopes should be mainly used, and scopes that inherit controller should be avoided as much as possible. According to my practice in the project, I feel that using the controller scope often causes various headaches.

    reply
    0
  • Cancelreply