I am using Angular v7.3.5 and I want to use a Service in a non-Angular class, something like this:
foo.model.ts
import { Foo2Service } from './foo2.service';
// Definition for FooClass (a model)
export class FooClass {
constructor(args: any) {
// Do something with args
}
func1() {
// -----> Use Foo2Service here <-------
}
}
foo2.service.ts
export class Foo2Service {
// Service code
constructor(private bar: BarService) {}
init() {
// Code that returns something
}
}
app.component.ts
import { FooClass } from './foo.model.ts';
export class AppComponent {
constructor() {
const foo = new FooClass('bar');
console.log(foo.func1());
}
}
Is it possible to do so? If yes, what is the best way to do it?
NOTE: I tried to use the Injector class provided by Angular but it didn't work for me. So please help.
barinstance coming from? (I am referring to codenew FooClass(bar);)stringor anobject. Fixed.