dongx
dongx

Reputation: 1800

How to access Angular 2 object's attribute

export class Dashboard {
    checked: Object = {users: false, device: false}
    boxClicked(){
        if(checked.users){
            console.log("clicked users");
        }
    }
}

Property 'users' does not exist on type 'Object'. Why?

Upvotes: 2

Views: 43

Answers (1)

Dylan Meeus
Dylan Meeus

Reputation: 5802

You are saying checked: Object = {users: false, device: false} which means that only those members defined 'Object' (the interface) will be visible. So you can not just access 'users'.

You should say checked: any = {users: false, device: false}

Upvotes: 3

Related Questions