当前第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中关于单元测试的面试题,你能回答上来吗?
详解Angular中自定义创建指令的方法
Angular和vue.js的区别是什么?Angular和vue.js的深度对比
浅谈Angular中父子组件间怎么传递数据
10个从喜到悲的Angular面试题
浅谈Angular中控制器、服务和指令的关系
Angular cli如果搭建Angular+typescript+material项目?
详解Angular中jsencrypt插件的使用方法
浅谈Angular中的component/service
浅谈Angular中的模块(ngmodule),延迟加载模块
更多相关阅读请进入《Angular》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 浅谈Angular中的DOM操作