Created
September 19, 2017 20:00
-
-
Save israeljrs/b21df582b33758d8d5735a30d4068925 to your computer and use it in GitHub Desktop.
sample use renderer2 with directive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, Renderer2, ElementRef, OnInit } from '@angular/core'; | |
@Directive({ | |
selector: '[appCp1]' | |
}) | |
export class Cp1Directive implements OnInit { | |
constructor(private renderer: Renderer2, private el: ElementRef) { } | |
ngOnInit() { | |
const li = this.renderer.createElement('li'); | |
const text = this.renderer.createText('Item 1'); | |
this.renderer.appendChild(li, text); | |
this.renderer.appendChild(this.el.nativeElement, li); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment