聚合物键合值不能改变

时间:2015-05-29 23:49:14

标签: javascript data-binding firebase polymer

点击后如何更改按钮内容? 在函数中我可以更改绑定值吗?

<dom-module id="my-facebook-login-button">
<template>
<paper-button on-click="facebookLogin">{{loginButton}}</paper-button>
</template>
</dom-module>
<script>
(function() {
Polymer({
  is: 'my-facebook-login-button',
  properties: {
    loginButton: {
      type: String,
      value: 'Login with facebook',
      notify: true 
    }
  },
facebookLogin: function() {
var ref = new Firebase("https://sizzling-heat-4021.firebaseio.com/");
ref.authWithOAuthPopup("facebook", function (error, authData) {
if (error) {
  console.log("Login Failed!", error);
} else {
  console.log("Authenticated successfully with payload:", authData);    
    app.user=authData;
    this.loginButton='Loged in';
}
});
},
});

})();
</script>

this.loginButton =&#39; Loged in&#39;不要改变按钮内容

1 个答案:

答案 0 :(得分:0)

在他的评论中,尼尔有正确的答案。使用bind。更新后的功能:

facebookLogin: function() {
  var ref = new Firebase("https://sizzling-heat-4021.firebaseio.com/");
  ref.authWithOAuthPopup("facebook", function (error, authData) {
    if (error) {
      console.log("Login Failed!", error);
    } else {
      console.log("Authenticated successfully with payload:", authData);    
      app.user=authData;
      this.loginButton='Logged in';
    }
  }.bind(this));
},