How to use a variable from a component in another in Angular2
Go to your app.module.ts and make the provider of that component you want to inherit with other classes:
Then go to the class you want access of that variable, and import the component into that:
Make the constructor of it:
And happily get access to the variables:
Yes possible, you can use the @Input()
method or use write get method like below
export class Demo {
const sum = 10;
get SumValue() {
return this.sum;
}
}
import-->Demo
export class Demo2 {
private sum: number;
this.sum = Demo.SumValue();
}