>我个人觉得不应该用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>
~~~
- 引言
- 安装angular9
- 入门
- 数据绑定
- 属性绑定
- 实体字符和转义
- html 模板运算
- css样式规范
- 数组与循环ngFor
- 条件ngIf
- 管道
- 事件执行
- 双向数据绑定mvvm
- todolist页面交互
- 公共服务层
- 数据持久化
- dom与ViewChild装饰器
- 父子组件传值
- 子父组件传值ViewChild
- 子父组件out装饰器
- 生命周期-挂/卸载
- es6语法io异步promise
- Rxjs异步数据流编程
- http_request
- axios异步数据
- 英雄route路由
- 动态route路由
- navigate route
- Parent child routing
- modularization
- lazyload