繁体   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