zoukankan      html  css  js  c++  java
  • elementRef

    elementRef.nativeElementk可以得到一个元素的引用,通过这个引用可以随意的操作dom样式

    import {Component, ElementRef, OnInit} from '@angular/core';
    
    @Component({
      selector: 'app-example1',
      templateUrl: './example1.component.html',
      styleUrls: ['./example1.component.css']
    })
    export class Example1Component implements OnInit {
    
      constructor(private el:ElementRef) {
    
      }
      show(){
        this.el.nativeElement.style.color="red";
        console.log(this.el.nativeElement)
      }
      ngOnInit() {
      }
    
    }
    
    

    获取元素的引用还有一种方法,通过吧$event传入事件中,就可以与拿到这个事件的所有属性,只要元素有事发生,就可以拿到元素的所有属性,换句话说,可以重写这个元素的样式

    e.target就是这个元素的引用

    You can change the world with your heart,even a lot of changes sometimes unless you won't geiv up....
  • 相关阅读:
    Codeforces 1230E
    扫描线求面积和周长 (模板,线段树)
    POJ2528
    线段树 (模板)
    Codeforces 1332B
    Codeforces 1279D
    Codeforces 1281B
    Codeforces 1288D
    8I
    8F
  • 原文地址:https://www.cnblogs.com/xiongwei2017/p/7075931.html
Copyright © 2011-2022 走看看