簡體   English   中英

如何在一個 angular 組件中從另一個組件調用 function(不同的.ts 文件)

[英]How to call a function in one angular component from another component(different .ts file)

文件1.ts

export class1(){
      dummy(a,b){
        ....
}
}

文件2.ts

export class2(){ 
     a: string = "scjhb"
     b: string ="mn hbh"
     //From here,I want to call dummy pass these parameters and call dummy function from file1.ts.How to do?
     dummy(a,b); //I want to call dummmy(a,b)    
}

i tried the below thing in File2.ts,but it's not working.

@ViewChild(class1, { static: false }) Classvar: class1; this.Classvar.dummy(a,b)

您可以簡單地擴展另一個類[繼承]。

提供 Stackblitz 示例: 示例

暫無
暫無

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

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