加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 当范围改变时,angular指令自动重新实例化

发布时间:2020-12-17 17:07:00 所属栏目:安全 来源:网络整理
导读:我的许多指令(很快将成为组件)从其他指令设置的变量中获取其范围.目前在每个指令中,我必须观察我的范围,以了解它是否已经改变,这似乎使代码不必要地复杂化.所以我开始在我的标签上使用ng-if =“vm.ready”来在需要时重新实现指令.但是那个国家的管理权被排除
我的许多指令(很快将成为组件)从其他指令设置的变量中获取其范围.目前在每个指令中,我必须观察我的范围,以了解它是否已经改变,这似乎使代码不必要地复杂化.所以我开始在我的标签上使用ng-if =“vm.ready”来在需要时重新实现指令.但是那个国家的管理权被排除在指令之外,而这个指令更难以维持.

我想知道如果您的指令的范围发生变化,那么angular是否提供了这样的机制,那么它至少会重新实现您的指令控制器.

谢谢

解决方法

你可以使用$onInit()

After the controller is instantiated,the initial values of the isolate scope bindings will be bound to the controller properties. You can access these bindings once they have been initialized by providing a controller method called $onInit,which is called after all the controllers on an element have been constructed and had their bindings initialized.

https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L250

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读