Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!