im new to typescript and angular 2 and what im trying to do is to create singletone to be used where ever is needed, but im getting this error:
Unexpected value 'ViewHelperComponent' declared by the module 'AppModule'
in the browser log, what am i doing wrong?
this is the class:
export class ViewHelperComponent {
static instance : ViewHelperComponent;
constructor() {}
public static getInstance(){
if(ViewHelperComponent.instance == null)
ViewHelperComponent.instance = new ViewHelperComponent();
return ViewHelperComponent.instance;
}
check(){
console.log("working");
}
}
and im calling it from this component:
import { Component} from '@angular/core';
import { ViewHelperComponent } from '../view-helper/view-helper';
@Component({
selector: 'app-input-parent',
templateUrl: './input-parent.component.html',
styleUrls: ['./input-parent.component.css']
})
export class InputParentComponent implements OnInit {
temp : ViewHelperComponent;
constructor() {
this.temp = ViewHelperComponent.getInstance()
}
}