Issue
Is it considered a good practice to use the keyword readonly
on @Input()
fields in Angular ?
Or are there any drawbacks ?
Solution
You won't be able to use the @Input()
field.
Error: src/app/app.component.html:6:12 - error TS2540: Cannot assign to 'foo' because it is a read-only property.
6 <app-test [foo]="5"></app-test>
~~~
You can get around this error by removing
"strictInputAccessModifiers": true
EDIT: So in conclusion, I would advise against it since strictInputAccessModifiers
does more than just throwing this particular error for this particular use case of readonly
. Although I do think there's some merit to blocking the manual assignment of @Input()
fields.
Answered By - Chris Gray
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.