首页 > 其他 > 详细

DOM in Angular2

时间:2016-12-30 16:25:42      阅读:223      评论:0      收藏:0      [点我收藏+]

<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

原文:http://www.cnblogs.com/haimingpro/p/6237241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!