gpt4 book ai didi

javascript - 如何访问 angularjs Controller 中的变量?

转载 作者:行者123 更新时间:2023-11-28 03:51:24 24 4
gpt4 key购买 nike

我有一个绑定(bind)eid: '@'

在我的构造函数中,我有一个方法:

this.$onInit = () => {
console.log('eid: ', this.eid)
}
console.log("eid in another place: ", this.eid)

当我执行此代码(通过输入应用程序的特定页面)时,我在控制台中看到

eid in another place:  undefined
eid: 1

如何传递 eid 变量以在 onInit 函数之外查看它?

最佳答案

尝试在日志中使用$ctrl特殊变量:

this.$onInit = () => {
console.log('eid: ', this.eid)
}
console.log("eid in another place: ", $ctrl.eid);

我创建了这个博客“Dissecting @ < & = bindings in AngularJS”,非常有帮助。

关于javascript - 如何访问 angularjs Controller 中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47969909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com