2017-07-16 63 views
0

我已經聲明的屬性是這樣的:改變屬性值在聚合物

static get properties() { 
     return { 
      auth1: { 
       type: Boolean, 
       readonly: false, 
       value: false, 
       notify: true 
      } 
     }; 
    } 
在我的聚合物元件

。現在我有這個功能:

connect(){ 
     this.auth1.value = true; 
     console.log("Authenticated" + this.authenticated); 

    } 

這應該改變屬性值爲true。每次我調用函數我有錯誤「TypeError:試圖分配給只讀屬性。」。但我已經在我的財產中只讀了假。我的功能被稱爲這樣一個按鈕: <button id="loginbutton" on-tap="connect">Click me!</button>

任何人都可以幫助我嗎?

+0

有一件事:O應該大寫:只讀:false – Bruce

+0

感謝您的提示! – Boerne

回答

1

問題在於屬性值的改變。

相反:

connect(){ 
     this.auth1.value = true; 
     console.log("Authenticated" + this.authenticated); 

    } 

的變化可以是這樣的:

connect() { 
    this.auth1 = true; 
    console.log("Authenticated" + this.auth1.value); 
} 

readonly: false是默認的,並且可以被刪除。

static get properties() { 
    return { 
     auth1: { 
      type: Boolean, 
      value: false, 
      notify: true 
     } 
    }; 
}