We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用 mdl 的界面包,动态加载 mdl 控件时必须获取 mdl 控件元素对其手动注册,ng2 中如何获取 DOM 元素
The text was updated successfully, but these errors were encountered:
可以通过注入ElementRef,访问nativeElement属性获取原始DOM
ElementRef
import {Component,ElementRef} from 'angular2/core'; @Component({ selector: 'App', providers: [], template: ` <h1>{{content}}</h1> ` }) export class App { content:string = 'Hello Kittencup'; constructor(public elementRef:ElementRef){ console.log(elementRef.nativeElement); } ngAfterViewInit(){ console.log(this.elementRef.nativeElement); } }
在constructor里获取的时候,template中得变量还未被渲染出来,这时候DOM结构是
constructor
template
<app> <h1></h1> </app>
在ngAfterViewInit周期中,如果对组件的生命周期还不了解的话,可以看下这里生命周期钩子,template已经被渲染出来了,这时候DOM结构是
ngAfterViewInit
<app> <h1>Hello Kittencup</h1> </app>
你可以根据你的需求选择不同时期的DOM
Sorry, something went wrong.
No branches or pull requests
用 mdl 的界面包,动态加载 mdl 控件时必须获取 mdl 控件元素对其手动注册,ng2 中如何获取 DOM 元素
The text was updated successfully, but these errors were encountered: