yiweiyihang
1.Angular 中的 dom 操作(原生 js)
ngAfterViewInit(){ 
var boxDom:any=document.getElementById(\'box\');
boxDom.style.color=\'red\'; }

2.Angular 中的 dom 操作(ViewChild)

/*
ViewChild获取dom节点:
1.模板中给dom起一个名字
<div #myBox>
  我是一个dom节点
</div>

2.在业务逻辑里面引入ViewChild
import { Component, OnInit,ViewChild } from \'@angular/core\';
3.写在类里面:
  @ViewChild(\'myBox\') myBox:any;
  4.ngAfterViewInit声明周期函数里面获取dom

*/
三、父子组件中通过 ViewChild 调用子组件的方法
1.调用子组件给子组件定义一个名称 
<app-footer #footerChild></app-footer>

2. 引入 ViewChild import { Component, OnInit ,ViewChild} from \'@angular/core\';

3. ViewChild 和刚才的子组件关联起来 @ViewChild(\'footerChild\') footer;

4.调用子组件 run(){this.footer.footerRun(); }

 

 

 

 

 

分类:

技术点:

相关文章:

  • 2022-01-24
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-28
  • 2021-06-16
  • 2022-12-23
  • 2021-11-02
  • 2022-02-23
  • 2021-12-04
  • 2022-01-19
相关资源
相似解决方案