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}`
);

最新文章

  1. vuex(1.0版本写法)
  2. RabbitMQ 集群安装过程详解
  3. Spring操作指南-针对JDBC配置声明式事务管理(基于XML)
  4. SQL Server备份脚本
  5. MVC5+EF6 Code First 从零开始——第一章
  6. Android 自定义波浪动画 --&quot;让进度浪起来~&quot;
  7. GUI用户界面编程
  8. 利用excel数据透视表实现快速统计相关数据
  9. python setup.py install 失败
  10. IOS 应用程序启动加载过程(从点击图标到界面显示)
  11. (转)Div+CSS布局入门
  12. JavaScript中的构造函数
  13. (精选)Xcode极速代码,征服Xcode,xcode插件
  14. Ocelot中文文档-GraphQL
  15. matplotlib.mlab库的重要函数
  16. gym 101755
  17. java中获取字母和数字的组合
  18. PMP 考试 形式
  19. synchronized、锁、多线程同步的原理是咋样
  20. git删除本地保存的账号和密码

热门文章

  1. Activity启动模式的深入分析
  2. Windows Server 2016 上配置 APACHE+SSL+PHP+perl
  3. Redis原理(二)
  4. Flask项目之手机端租房网站的实战开发(四)
  5. uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)
  6. Android EditText回车不换行
  7. (转)30 IMP-00019: row rejected due to ORACLE error 12899
  8. GDB中创建要素数据集
  9. 仿招商银行载入loading效果
  10. 高效的敏感词过滤方法(PHP)