第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

非角度類如何使用角度服務(wù)及其部門

非角度類如何使用角度服務(wù)及其部門

SMILET 2023-04-20 17:14:41
我正在嘗試鏈接 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() {    }}
查看完整描述

1 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

您可以將CommonCodeTS 類轉(zhuǎn)換為 Angular 服務(wù)并在組件級(jí)別提供它。


@Component({

? selector: 'my-app',

? templateUrl: './app.component.html',

? styleUrls: [ './app.component.css' ],

? providers: [ CommonCode ],

})

export class AppComponent? {


? ngOnInit() {


? }

}


查看完整回答
反對(duì) 回復(fù) 2023-04-20
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)