多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
>我个人觉得不应该用dom操作,都用angular了,还用jq一样的dom操作 ??? >在header.component.ts子组件中定义 一个变量和方法 ~~~ public childMsg:string='我是header子组件的msg'; public childFunction():void{ alert("我是header子组件的方法"); } ~~~ >在index.html父组件中 绑定dom 为aaa ~~~ <app-header [title]="title" [fatherFunction]="fatherFunction" #aaa></app-header> ~~~ >在index.component.ts中 使用viewChild 模块 装饰器 赋值变量 ~~~ import { Component, OnInit,ViewChild } from '@angular/core'; export class IndexComponent implements OnInit { @ViewChild('aaa') aaa:any; public getChildMsg():void{ alert( this.aaa.childMsg); } public getChildFunction():void{ this.aaa.childFunction(); } } ~~~ >index.html 父组件中 使用调用子组件方法 ~~~ <button (click)="getChildMsg()">子组件的变量</button> <br> <button (click)="getChildFunction()">子组件的方法</button> ~~~