October 2017
Intermediate to advanced
280 pages
6h 50m
English
The @Input and @Output decorators are syntax sugar for easier declaration of the directive's inputs and outputs. The original syntax for this purpose is as follows:
@Directive({
outputs: ['outputName: outputAlias'],
inputs: ['inputName: inputAlias']
})
class Dir {
outputName = new EventEmitter();
}
Using @Input and @Output, the preceding syntax is equivalent to this:
@Directive(...)
class Dir {
@Output('outputAlias') outputName = new EventEmitter<any>();
@Input('inputAlias') inputName: any;
}
Although both have the same semantics, according to the best practices, we should use the latter one, because it is easier to read and understand.
Read now
Unlock full access