简体   繁体   中英

change property value in polymer

I have declared a property like this:

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

in my Polymer element. Now I have the function:

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

    }

which should change the property value to true. Everytime I call the function I am having the error "TypeError: Attempted to assign to readonly property.". But I have set readonly to false in my property. My function is called with a button like this: <button id="loginbutton" on-tap="connect">Click me!</button>

Can anybody help me?

The problem was in the changing of the property value.

Instead:

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

    }

The change can be like this:

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

readonly: false is the default, and can be removed.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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