Home > Enterprise >  How to type the Components.inputs array in angular
How to type the Components.inputs array in angular

Time:11-11

I noticed that in angular you can define inputs inside the @component decorator

@Component({
   selector: 'my-component',
   changeDetection: ChangeDetectionStrategy.OnPush,
   template: '<ng-content></ng-content>',
   inputs: ['first', 'last', 'middle']
})
export class ...

But how can one now type the inputs, which you simply can do with @Input

@Input() first: string;

CodePudding user response:

Try this

inputs: ['name', 'id: number'],

This is a string array by default. Now, create your property in class as

id: number (without @Input)

  • Related