[英]Polymer not changing value of defined property
我正在使用digits-api登录。 我正在使用附加的生命周期事件在附加时初始化脚本。
attached: function(){
console.log("Attached")
Digits.init({ consumerKey: '************' });
}
然后,在单击按钮时,用户可以登录。
onLoginButtonTap : function(){
Digits.logIn().done(this.onLogIn).fail(this.onFail);
},
用户成功登录后,它将转到onLogIn函数。
onLogIn: function() {
console.log("Login Successfull");
this.loginStatus="Log Out"
}
因此,我要做的是将纸质按钮内的文本从“登录”更改为“注销”。 我有一个属性登录状态。
loginStatus:{
type : String,
value: "Log In",
notify: true,
reflectToAttribute: true
}
当我尝试使用this.loginStatus =“ Log Out”更改onLogIn方法中的文本时。 它说Uncaught TypeError:无法设置未定义的属性'loginStatus'。 所以基本上我在其他代码中也看到了这一点。 我无法访问函数内函数内部元素的ID。 这里同样是我无法在函数内部更改函数中属性值的问题。 我如何从这个问题中恢复过来。
<paper-button raised class="custom indigo" id="logIn">[[loginStatus]]</paper-button>
错误消息表明this
是undefined
。 对于您的情况,在指定回调时应this
绑定 :
Digits.logIn().done(this.onLogIn.bind(this)).fail(this.onFail.bind(this));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.