zoukankan      html  css  js  c++  java
  • [Angular] Using the platform agnostic Renderer & ElementRef

    ElementRef:

    ElementRef is a way to access native html element, notice that it only works for Broswer.

    Render:

    Render helps to take care of different platforms (mobile or browser). It is recommended to use Render to change DOM instead of using ElementRef directly.

            <label>
              Email address
              <input type="email" name="email" ngModel #email>
            </label>
    export class AuthFormComponent implements AfterViewInit {
    
      @ViewChild('email') email: ElementRef;
    
      constructor(
        private renderer: Renderer
      ) {}
    
      ngAfterViewInit() {
        this.renderer.setElementAttribute(this.email.nativeElement, 'placeholder', 'Enter your email address');
        this.renderer.setElementClass(this.email.nativeElement, 'email', true);
        this.renderer.invokeElementMethod(this.email.nativeElement, 'focus');
        // this.email.nativeElement.setAttribute('placeholder', 'Enter your email address');
        // this.email.nativeElement.classList.add('email');
        // this.email.nativeElement.focus();
      }
    
    ...
    
    }

    Another example:

    this.loadingService.duration: '2s'

    //from   
      this.el.nativeElement.style.setProperty(
          "--duration",
          this.loadingService.duration
        );
    
    
    // to
        this.render.setAttribute(
          this.el.nativeElement,
          "style",
          `--duration:${this.loadingService.duration}`
        );
  • 相关阅读:
    .net core相关博客
    通过几个Hello World感受.NET Core全新的开发体验
    ASP.NET Core 介绍
    ASP.NET MVC4企业级实战目录
    ASP.NET MVC4入门到精通系列目录汇总
    HTTP详解
    壮哉大微软,.Net人的春天来了,你准备好了嘛!
    简析 .NET Core 构成体系
    .Net Core[译文]
    OI再见
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6436461.html
Copyright © 2011-2022 走看看