I am new to Angular 2 and TypeScript and I'm trying to following code in which I want to use the variable of Test class in my another component viz header.
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
export class Test{
static var1:number=10;
}
var1 is static because I want to use it without making test instance.
Code in the another component viz header
import { Component, OnInit } from '@angular/core';
import {Test} from '../app.component';
@Component({
selector: 'app-header',
Template;`<h1> Hello</h1>
<h1>{{Test.var1}}</h1>`
})
export class HeaderComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
This code showing only hello not "10" which is a static variable.
Thank you in advance.
obj.var1
is used in template But not showing me 10 as a output – Pulkit Aggarwal Apr 12 '17 at 10:47