I was attempting to answer someone elses question. And in doing so realised there was quite a bit of uncertainty in my mind about a few things. I\'m hoping someone can provide f
None of them worked for me.. Finally found solution by creating custom directive angular.. Directives are powerful feature of angular
@Directive({
selector: '[readonly],[readOnly]',
host: {
'[attr.readonly]': '_isReadonly ? "" : null'
}
})
class ReadonlyDirective {
_isReadonly = false;
@Input() set readonly (v) {
this._isReadonly = coerceBooleanProperty(v);
};
ngOnChanges(changes) {
console.log(changes);
}
}
@NgModule({
...
declarations: [ ..., ReadonlyDirective ],
...
})
or
Demo https://stackblitz.com/edit/angular-readonly-input-aifncy?file=src/app/app.component.ts