In AngularJs we could make a directive attribute required. How do we do that in Angular with @Input? The docs don\'t mention it.
Eg.
@Component({
selec
For me, I had to do it this way:
ngOnInit() {
if(!this.hasOwnProperty('a') throw new Error("Attribute 'a' is required");
}
FYI, If you want to require @Output directives, then try this:
export class MyComponent {
@Output() myEvent = new EventEmitter(); // This a required event
ngOnInit() {
if(this.myEvent.observers.length === 0) throw new Error("Event 'myEvent' is required");
}
}