javascript - Why is `@input` decorator preferred over `inputs:[]` -
there 2 ways define input on component:
@component({ inputs: ['displayentriescount'], ... }) export class mytable implements oninit { displayentriescount: number;
and this
@component({ ... }) export class mytable implements oninit { @input() displayentriescount: number;
i assume first approach better since explicitly declares component's dependencies without need inspect complements class. however, this article renowned developer states second approach preferable:
using @input preferred approach, don’t have use it.
any ideas why?
per angular style guide https://angular.io/docs/ts/latest/guide/style-guide.html#!#-a-id-05-12-a-decorate-input-and-output-properties-inline
decorate input , output properties inline
do use @input , @output instead of inputs , outputs properties of @directive and@component` decorators:
do place @input() or @output() on same line property decorate.
why? easier , more readable identify properties in class inputs or outputs.
why? if ever need rename property or event name associated @input or @output, can modify single place.
why? metadata declaration attached directive shorter , more readable.
why? placing decorator on same line makes shorter code , still identifies property input or output.
Comments
Post a Comment