Angular使用 ElementRef + Renderer2 全局設置組件屬性


1.引入元素選擇器

 

 

 

2.使用angular鈎子全局設置input長度

ngAfterViewChecked() {
    const input = this.el.nativeElement.querySelectorAll('input');
    if (input) {
      input.forEach(e => {
        this.renderer.setAttribute(e, 'maxlength', '1');
        // console.log(e);
      });
    }
  }

3.如果項目是采用framework式布局 可以全局設置容器內的頁面組件的屬性

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM