I have a unique situation with my component setup
export class Component1Component implements OnInit {
public greetings: string ="";
constructor(private greeter: Greeter) { }
ngOnInit() {
this.greetings = this.greeter.sayHello();
}
}
The structure of the Greeter class is as follows:
export class Greeter{
private hello_greetings = "Hello";
constructor(){}
public sayHello():string {
return this.hello_grittings;
}
}
A factory provides the Greeter class:
export function GreeterFactory():Greeter { return new Greeter(); }
@NgModule({
providers: [
{ provide: Greeter,
useFactory: GreeterFactory,
multi: true
}
]
})
Upon loading Component1, I encounter the following error:
AppComponent.html:1 ERROR TypeError: this.greeter.sayHello is not a function at Component1Component.ngOnInit (component1.component.ts:36)
When printing this.greeter in the OnInit method, the output is:
[{"hello_greetings":"Hello"}]
It appears that the class is being injected correctly, but the methods are not found during runtime. Any assistance would be greatly appreciated.
You can access the entire project here
Thank you for your help!