zszep
zszep

Reputation: 4483

How to detect attribute change in angular 2?

Given the following code:

Parent component:

<my-cmp readonly></my-cmp>

Child component:

...
constructor(@Attribute('readonly') readonly) {
    this._readonly = readonly !== null ? 1 : 0;
  }
...

How do I detect changes to the readonly attribute?

Upvotes: 1

Views: 937

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 658175

@Input()
set readonly(val) {
 if(val === '') {
  console.log('set');
 } else {
  console.log('removed'); 
}

Upvotes: 1

Related Questions