Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda