Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
How to pass a class component value to custom decorator in Angular?

When I tired to access an angular component value inside a custom decorator, I am getting an error stating this is not defined. From online documentation, I have found out that decorator function will get called first even before the class initialization. Because of this decorators will not have access to instance variables.

Note: I have tried creating a static variable and tried to access the static variable inside the custom decorator. Only problem with this approach is customDecorator runs first before assigning the value to static variable. Hence the AccountId is undefined when i tried to access inside customDecorator.

How I can access this AccountId inside the custom decorator? Any help would be greatly appreciated.

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

@Component({
  selector: 'app-account-display',
  templateUrl: './accounts.component.html',
  styleUrls: ['./account s.component.scss']
})
export class AccountsComponent implements OnInit {

  @Input() AccountId: string
  constructor() {
    
  }
  
  @CustomDecorator(this.AccountId)

  ngOnInit() {
  }
  ...........................
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

hu Ane!

if AccountId is passed statically from parent you can simply:

ngOnInit() {
console.log(this.AccountId)
  }

if AccountId is asynchronous you can do something like this

@Input() get AccountId(value: string) {
 if(value) {
  this.accountID$.next(value)
 }
}

accountId$ = new ReplaySubject<any>()
ngOnInit() {
this.accountId$.subscribe((x) => console.log(x) )   <-- remember to unsubscribe
  }

here you can find more info

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda