首页 > 代码库 > DOM in Angular2
DOM in Angular2
<elementRef>
import {ElementRef} from "@angular/core";
constructor(private element: ElementRef) { // now, we can reference to: this.element}
this.element.nativeElement(‘.js-banner-container‘),
ElementRef
Provides access to the underlying native element (DOM element).
import {AfterContentInit, Component, ElementRef} from ‘@angular/core‘;@Component({ selector: ‘app‘, template: ` <h1>My App</h1> <pre style="background: #eee; padding: 1rem; border-radius: 3px; overflow: auto;"> <code>{{ node }}</code> </pre>`})export class App implements AfterContentInit { node: string; constructor(private elementRef: ElementRef) { } ngAfterContentInit() { const tmp = document.createElement(‘div‘); const el = this.elementRef.nativeElement.cloneNode(true); tmp.appendChild(el); this.node = tmp.innerHTML; }}
参考这篇 Angular 2: @Directive() 指令创建无限滚动
DOM in Angular2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。