Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to access variable from another component in angular

Go to your app.module.ts and make the provider of that component 
you want to inherit with other classes:

Ex: providers: [DatePipe, AccountComponent]


Then go to the class you want access of that variable, 
and import the component into that:

Ex: import { AccountComponent } from '../account/account.component';


Make the constructor of it:

Ex:
constructor(private accountComponent: AccountComponent){}

And happily get access to the variables:
Ex: this.url = this.accountComponent.apiEndPoint+'hello';
 
PREVIOUS NEXT
Tagged: #access #variable #component #angular
ADD COMMENT
Topic
Name
5+7 =