我正在嘗試鏈接 3 個(gè)文件 Angular 組件、Plain JS 類和 Angular 服務(wù):我的角度組件(AppComponent)應(yīng)該初始化我的普通 js 類(CommonCode)...但是,我的普通 js 類需要調(diào)用和角度服務(wù)。成分:@Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ]})export class AppComponent { ngOnInit() { }}服務(wù):import { AnotherAngularService } from '/core/service2';import { AnotherAnotherAngularService } from '/core/service3';@Injectable({ providedIn: 'root',})export class Foo2Service { this.serviceOneCache = null; // Service code constructor(public anotherAngularService:AnotherAngularService, public anotherAnotherAngularService:AnotherAnotherAngularService) { this.anotherAngularService.getCache().subscribe(response) { this.serviceOneCache = response; } .error(); } init() { // Code that returns something return 'test'; } getFooCache() { return this.http.get...... etc etc }}JS類import { FooService } from '/core/fooservice';export class CommonCode { this.fooCache = null; // Service code constructor(public fooService: FooService) { this.fooService.getFooCache().subscribe(response) { this.fooCache = response; } .error(); } func1() { }}
非角度類如何使用角度服務(wù)及其部門
SMILET
2023-04-20 17:14:41