简体   繁体   English

如何在一个 angular 组件中从另一个组件调用 function(不同的.ts 文件)

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

File1.ts文件1.ts

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

File2.ts文件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; @ViewChild(class1, { static: false }) Classvar: class1; this.Classvar.dummy(a,b) this.Classvar.dummy(a,b)

You can simply extends another class[inheritance].您可以简单地扩展另一个类[继承]。

Providing Stackblitz example: Example提供 Stackblitz 示例: 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 service.ts 文件中的 Component.ts 文件调用 function,该文件在 angular 的同一组件中 - How to Call function from Component.ts file in service.ts file which is in the same component in angular Angular2从另一个组件调用一个函数组件 - Angular2 call one function component from another component 如何从另一个组件调用函数 [Angular] - How to call a function from another component [Angular] 如何在component.ts中将数据从一个函数传递到另一个函数,angular2 - how to pass data from one function to another in component.ts , angular2 如何从另一个组件调用一个组件中的方法是 angular2 - how to call a method in one component from another component is angular2 如何从 angular 中的 model 组件调用另一个组件 function? - How to call another component function from model component in angular? 如何从 Angular 中的另一个组件调用组件的 ngOnit function - How to call ngOnit function of a component from another component in Angular 如何从另一个组件调用一个组件函数 - How to call one component function from another component 如何在角组件TS中调用组件 - How to call a component inside component TS in angular 如何从另一个组件中的组件调用函数? - How to call a function from a component in another component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM