0
have the following doubt:
Today as far as I have seen there are 2 ways to receive information in an Angular Component.
But I doubt the question "performance".
The example below I import the Input from the "@angular/core package":
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-meu',
template: `<h1>Meu nome é {{ meuNome }}</h1>`
})
export class MeuComponent {
@Input('nome') meuNome: string = '';
constructor() {}
}
Already 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 could use my component, passing the attribute [nome]
and function.
But using the @Input()
i find it more elegant and easier to orient yourself in developing on what is input Property or what is variable from my class.
Then comes the doubt, the fact of using the @Input()
makes code slower? What is best practice?
The logic of the Developer
@Input
is to pass values from a Componentpai(parent)
for a Componentfilho(children)
.– Marconi
Thanks @Marconi! I understand the use of the Developer. The question was about the performance itself. That is why there are two ways.
– Hiago Souza
Hiago, the way I see it, you didn’t use the
decorator
correctly, both forms do not require the@Input
– Marconi
@Marconi but it was just an example I used at the time to present my doubt.
– Hiago Souza
In this example I would use <app-my name="hiago"></app-my>
– Hiago Souza
Got it, I thought it’s developing like rs. D
– Marconi
What you could do is run the developer tools at 3g slow speed and see which pulls the value in less time than
ms
ors
, I believe it may be that with the note@Input
is faster by going directly to the correct method– Gaspar