当前第2页 返回上一页
1 2 3 | < div #myBox>
我是一个dom节点
</ div >
|
2、现在组件ts通过ViewChild 获取dom
1 2 3 4 | < div #myBox>我是一个dom节点</ div >
< app-header #header></ app-header >
< button type = "button" (click)='getChildProp()'>获取子组件header的属性</ button >
< button type = "button" (click)='getChildMethod()'>获取子组件header的方法</ button >
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | import { Component, OnInit, ViewChild } from '@angular/core' ;
@Component({
selector: 'app-news' ,
templateUrl: './news.component.html' ,
styleUrls: [ './news.component.less' ]
})
export class NewsComponent implements OnInit {
@ViewChild( 'myBox' )
public myBoxIn: any;
@ViewChild( 'header' )
public header: any;
constructor() { }
ngOnInit(): void {
}
ngAfterViewInit() {
console.log( this .myBoxIn.nativeElement)
console.log( '父组件获取到了整个子组件header' )
console.log( this .header)
}
getChildProp() {
console.log( this .header.title)
}
getChildMethod() {
console.log( this .header.headRun)
this .header.headRun();
}
}
|
更多编程相关知识,请访问:编程入门!!
以上就是浅谈Angular中的DOM操作的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
浅谈Angular cli工具如何从零搭建并运行一个简单项目
浅谈Angular控制器通信的4种方式
如何利用管道提高Angular应用程序的性能?
2021年值得尝试的7个Angular前端组件库,快来收藏吧!
浅谈Angular中父子组件间相互传参的方法
详解Angular中的observable(可观察对象)
浅谈Angular中如何添加和使用font awesome
浅谈Angular中@viewchild的用法
分享Angular中关于表单的一些知识点
浅谈Angular中父子组件相互传参的方法
更多相关阅读请进入《Angular》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 浅谈Angular中的DOM操作