angular8 大地老师学习笔记---第八课
2024-09-08 02:45:20
/*
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
this.myBox.nativeElement
*/
import { Component, OnInit,ViewChild} from '@angular/core';
@Component({
selector: 'app-news',
templateUrl: './news.component.html',
styleUrls: ['./news.component.scss']
})
export class NewsComponent implements OnInit {
//获取dom节点
@ViewChild('myBox') myBox:any;
//获取一个组件
@ViewChild('header') header:any;
constructor() { }
ngOnInit() {}
ngAfterViewInit(): void {
console.log(this.myBox.nativeElement);
this.myBox.nativeElement.style.width='100px';
this.myBox.nativeElement.style.height='100px';
this.myBox.nativeElement.style.background='red';
console.log(this.myBox.nativeElement.innerHTML);
}
getChildRun(){
//调用子组件里面的方法
this.header.run();
}
}
最新文章
- ★Kali信息收集~3.子域名系列
- 学习笔记——SQLite介绍
- 使用jQuery加载script脚本
- PHP设计模式(一)
- Bean
- linux 常用的基本命令
- Spring shiro使用
- 夺命雷公狗ThinkPHP项目之----企业网站24之网站前台列表页面包屑导航的显示
- MongoDB备份与导入
- 从win7到mac os再到win10,体验总结
- JQ 一些基本方法
- SQL总结之对比和备份
- 《JAVASCRIPT高级程序设计》客户端检测
- suse安装svn服务端和客户端的使用
- 安装git,gitlab和TortoiseGit
- JVM内存异常与常用内存参数设置总结
- sql查询语句for xml path语法
- linux(centos 7)下安装elasticsearch - head插件(端口占用,防火墙关闭)
- centos 下python升级
- HDU - 4511 小明系列故事――女友的考验(AC自己主动机+DP)
热门文章
- C语言讲义——错误处理
- 题解 洛谷 P2612 【[ZJOI2012]波浪】DP+高精
- LeetCode 044 Wildcard Matching
- OllyDbg使用入门
- C#:终于有人把 ValueTask、IValueTaskSource、ManualResetValueTaskSourceCore 说清楚了!
- 定时器:Django-crontab
- 第7.27节 Python案例详解: @property装饰器定义属性访问方法getter、setter、deleter
- Python学习随笔:使用xlwings读取和操作Execl文件
- Project Lombok——带给你简洁、清晰的代码
- WPF页面刷新