1

我有一个绑定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函数外部查看它?

4

1 回答 1

0

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

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

我创建了这个博客“在 AngularJS 中剖析 @ < & = 绑定”非常有帮助。

于 2017-12-25T18:51:31.487 回答