简体   繁体   English

聚合物不改变定义特性的值

[英]Polymer not changing value of defined property

I am using digits-api for login. 我正在使用digits-api登录。 I am initializing the script on attach using attached life cycle event. 我正在使用附加的生命周期事件在附加时初始化脚本。

attached: function(){
         console.log("Attached")
         Digits.init({ consumerKey: '************' });
        }

Then On clicking the Button it user can login. 然后,在单击按钮时,用户可以登录。

onLoginButtonTap : function(){
        Digits.logIn().done(this.onLogIn).fail(this.onFail);
        },

When the user successfully login it will go to onLogIn function. 用户成功登录后,它将转到onLogIn函数。

onLogIn: function() {
            console.log("Login Successfull");
            this.loginStatus="Log Out"
        }

So what I am doing is changing text inside paper button from Log In to Log out. 因此,我要做的是将纸质按钮内的文本从“登录”更改为“注销”。 I have a property login status. 我有一个属性登录状态。

loginStatus:{
      type : String,
      value: "Log In",
      notify: true,
      reflectToAttribute: true
      }

When I try to change text in onLogIn method using this.loginStatus="Log Out". 当我尝试使用this.loginStatus =“ Log Out”更改onLogIn方法中的文本时。 It says Uncaught TypeError: Cannot set property 'loginStatus' of undefined. 它说Uncaught TypeError:无法设置未定义的属性'loginStatus'。 So basically I saw this in my other codes too. 所以基本上我在其他代码中也看到了这一点。 I am not able to access ids of elements inside function inside a function. 我无法访问函数内函数内部元素的ID。 Same is the matter here I am not able to change value of property in function inside a function. 这里同样是我无法在函数内部更改函数中属性值的问题。 How do I recover from this problem. 我如何从这个问题中恢复过来。

<paper-button raised class="custom indigo" id="logIn">[[loginStatus]]</paper-button>

The error message indicates that this is undefined . 错误消息表明thisundefined In your case, you should bind this when specifying the callback: 对于您的情况,在指定回调时应this绑定

Digits.logIn().done(this.onLogIn.bind(this)).fail(this.onFail.bind(this));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM