Typescript 如何在一个组件中调用方法,而它将在另一个组件中调用另一个方法?
我对angular不太熟悉,所以组件扩展对我来说很混乱。我有两个组件,如标题和内容。所以我在header组件中有一个类似filterChange()的方法,所以当我调用这个方法时,它应该调用另一个组件中的另一个方法。我尝试了@input和@output,但在那里我无法调用这些方法 标题组件html:Typescript 如何在一个组件中调用方法,而它将在另一个组件中调用另一个方法?,typescript,angular8,Typescript,Angular8,我对angular不太熟悉,所以组件扩展对我来说很混乱。我有两个组件,如标题和内容。所以我在header组件中有一个类似filterChange()的方法,所以当我调用这个方法时,它应该调用另一个组件中的另一个方法。我尝试了@input和@output,但在那里我无法调用这些方法 标题组件html: <mat-radio-group[(ngModel)]="visibility" (ngModelChange)="filterChange()">
<mat-radio-group[(ngModel)]="visibility" (ngModelChange)="filterChange()">
<mat-radio-button [value]=null>true</mat-radio-button>
<mat-radio-button *ngFor="let visibility of jobVisibilities"
[value]="visibility">false</mat-radio-button>
</mat-radio-group>
这是我的密码。我也尝试过服务,但我不知道怎么做。
如何做到这一点?请帮我修一下这个?哇!谢谢@lliyas…不用服务,我得到了这个答案。
Lets say u have 2 components ***HeaderComponent.ts*** and ***ContentComponent.ts***
U want to call the test() function from header component, which is in Content component
* Import the ***content component***
import {classname} from ./../content.component.ts;
* Give the dependency injection
constructor(){ public content : classname }
filterChange(){
/*you can call any content component function here*/
let sample = this.content.test()
console.log(sample)
}
Lets say u have 2 components ***HeaderComponent.ts*** and ***ContentComponent.ts***
U want to call the test() function from header component, which is in Content component
* Import the ***content component***
import {classname} from ./../content.component.ts;
* Give the dependency injection
constructor(){ public content : classname }
filterChange(){
/*you can call any content component function here*/
let sample = this.content.test()
console.log(sample)
}