angular 获取Dom

## ViewChild { (#App)

    viewChild 接收二个参数 ,第二个为 {static :true } 因为 angular8 会计算模板的查询时间 ,static 是静态的意思。 如果使用了 ngif 判断则为动态 {static : false}
    1. 获取组件实例( NzComponent , { static:true }) private nz: NzComponent --nz 为实例名称
    2. 定义Dom节点@ViewChild('App', {static: true}) priavate app: ElementRef
       获取Dom节点值 this.app.nativeElement
       保存Dom节点值 private saveApp: HTMLDivElement (saveApp数据类型: HTMLDivElement)
       赋值Dom节点值 this.saveApp = this.app.nativeElement
}

猜你喜欢

转载自blog.csdn.net/Tom__cy/article/details/104251005