In the last few days I made two providers for my app. Now I have to start a function from the first provider in the second one. Is this possible?
afo.ts:
export class Afo {
foo(): void {
console.log('foo');
}
}
bfo.ts:
@Injectable()
export class Bfo {
private _afo:Afo;
constructor(afo:Afo) {
this._afo = afo;
}
bar():void {
this._afo.foo();
}
}
Sorry, I don’t get it right.
Don’t I’ve to import the second provider or something else?
I’m facing thes same problem, but wasn’t able to transfer your example to a working version of my problem.
Yes. Your IDE should take care of doing that for you. BTW, over the course of the last year I learned that TypeScript will automatically generate properties for you if you put access qualifiers on constructor parameters, so there’s not any need to explicitly declare _afo
; one could just say constructor(private _afo: Afo)
.
Hm, I’ m using VisualStudio Code and it just says:
Cannot find name
Then I guess you’ll have to type import {OtherProvider} from "../path/to/other/provider";
yourself. In IDEA the identifier turns red and when I press alt-enter it automatically finds and adds the import.
Oh, thanks, I struggled with the path, but it wasn’t too difficult to figure this out with some clear thoughts…
My path (all providers are in the same directory:
import { Afo } from '../providers/afo';