dongx dongx - 4 months ago 9
AngularJS Question

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?

Answer

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}

Comments