Use the decorator Input or declare in the meta data?

0

I have the following question:

Today, as far as I can see, there is a way to receive information in a Component of the Angular.

But I am in doubt about the "performance" issue.

  

The following example I do the import of the package "@ angular / core":

import { Component, Input } from '@angular/core';

@Component({
    selector: 'app-meu',
    template: '<h1>Meu nome é {{ meuNome }}</h1>'
})
export class MeuComponent {
     @Input('nome') meuNome: string = '';
     constructor() {}
}
  

In the example below I do the same thing without the need to import

import { Component } from '@angular/core';

@Component({
    selector: 'app-meu',
    template: '<h1>Meu nome é {{ meuNome }}</h1>',
    inputs: ['meuNome:nome']
})
export class MeuComponent {
     meuNome: string = '';
     constructor() {}
}

In both cases I would be able to use my component, passing the [nome] attribute and it would work.

But using @Input() I find it more elegant and easier to orient in the development of what is input property or what is variable in my class.

Then comes the doubt, does using @Input() make the code slower? What is the best practice?

    
asked by anonymous 04.10.2017 / 15:07

1 answer

0

According to the Angle's style guide , it is advisable to use @Input. The use of @Input may make it easier in some cases. According to this post: angular use input says that in some cases it may be that the variable with the use of inputs inside the component is not recognized.

    
04.10.2017 / 17:03