-
Notifications
You must be signed in to change notification settings - Fork 27k
Description
🚀 feature request
Relevant Package
This feature request is for @angular/coreDescription
A clear and concise description of the problem or missing capability...When you are writing a component, there are usually some vital inputs need to be ready for your component to work/render properly. The problem is these inputs may not be ready at the component instantiate time. To guard this scenario, the component author usually needs to provide some default values to these inputs, so the null/undefined inputs field won't break your component. But not every input type has an obvious default. For example, an object input will require to write a long object literal or your need to add a bunch of safe operator ?. in your template. A function as an input is another example.
Describe the solution you'd like
If you have a solution in mind, please describe it.If we can have a decorator, say @required and use it like:
export class SomeComponent { @Required @Input requiredProperty; }
and usage of the component:
<some-component [requiredProperty]="asyncData"></some-component>
will be equivalent to
<some-component *ngIf="requiredProperty" [requiredProperty]="asyncData"></some-component>
I believe there are many benefits if we have this capability:
- It specifies a clear contract what component author expects component users to provide.
- Component author no longer needs to worry the inputs are in inconsistent state while waiting they arrive.
- It relieve the component users the burdens to write those *ngIf check. Image if a component has 4 or more required inputs.
- The component users may even get a compiler warning/error when they forget to bind some required inputs.
Am I too naive? Does this make sense?