簡體   English   中英

從角度中的組件訂閱擴展.ts文件時返回成功數據

[英]return success data while subscribing in extend .ts file from component in angular

我在擴展為.ts文件時嘗試從組件中的.subscribe返回成功(結果)數據

擴展像appConfig這樣的ts文件並使用返回值調用方法的相應組件中的方法/結果是一個好主意。

它是否會影響擴展相同單個appConfig文件的組件?

app.component.ts

export class viewComponent extends appConfig OnInit {
constructor(
public service: httpservice
){
super(service);
}
getData(){
        let data = this.mserviceCall('resolveId',"sjsjs-1092");
        debugger;
        if(data && Object.keys(data).length > 0){
            alert(data) <=== data is required here
        }
    }
}

app.component.html

<button class="btn" type="button" (click)="getData()">Get</button>

appConfig.ts

public mserviceCall(type, id) {
    const _self = this;
    if (type === 'resolveId') {
        let _params;
        _params = {
            'kid': id
        };
           this.serviceInvoker.invoke('resolve.information', _params).subscribe(
            (result) => {
                if (result) {
                    return result;
                }
            },
            (error) => {
            }
        );
    }
}

擴展像appConfig這樣的ts文件並使用返回值調用方法的相應組件中的方法/結果是一個好主意。

我不這么認為。 您應該考慮使用服務來分隔應用程序中的不同角色(邏輯和視圖)。

它是否會影響擴展相同單個appConfig文件的組件?

不,他們是不同的實例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM