项目场景:
Angular 版本 11
"@angular/animations": "11.2.5",
"@angular/cdk": "11.2.4",
"@angular/common": "11.2.5",
"@angular/compiler": "11.2.5",
"@angular/core": "11.2.5",
"@angular/forms": "11.2.5",
"@angular/localize": "11.2.5",
"@angular/platform-browser": "11.2.5",
"@angular/platform-browser-dynamic": "11.2.5",
"@angular/router": "11.2.5",
描述:
要从封装后的SF模块(表格搜索模块)去更改里面一层的值, 或者调用其中的方法
解决方案:
在父模块的template
标签中增加 #child1
@Component({
selector: 'sf-rms-motorcade-select-search',
template: `
<child #child1
</child>
`,
preserveWhitespaces: false,
})
export class MotorcadeSelectSfComponent
获取子组件的引用
@ViewChild('child1')
child1: ChildComponent; // 父组件中获得子组件的引用
然后就可以随意操作子组件
this.child1.value = "test";