DOM operation in the angular

 

 

 

 

 

 

 

 

 

 

 

ngAfterViewInit(): void {
    // DOM loaded lifecycle functions, get in here DOM
    let dom2: any = document.getElementById('dom2')
    console.log(dom2)
    dom2.style.color = 'blue'
   
  }

 

 

 

 

 

 

<div #myDom > house house house </ div>

 

 

 

 

 

@ViewChild('myDom', null) myDom: any
  ngOnInit () {
    console.log(this.myDom, "00000")
    this.myDom.nativeElement.style.width= '100px'
    this.myDom.nativeElement.style.height= '100px'
    this.myDom.nativeElement.style.backgroundColor= 'pink'

 

Guess you like

Origin www.cnblogs.com/monkey-K/p/11567098.html