I am writing a component where I need access to the native element. I am doing it like this now by getting it in
ngOnInit()
See this plunk.
import {Component, Input, ViewChild, Renderer} from 'angular2/core';
@Component({
selector: 'audio-preview',
template: `
<audio controls #player [attr.src]="src">
<source [src]="src" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
`
})
export class AudioPreview {
@Input() src: string;
@ViewChild('player') player;
constructor(public renderer: Renderer) {}
ngAfterViewInit() {
console.log(this.player);
// Another way to set attribute value to element
// this.renderer.setElementAttribute(this.player, 'src', this.src);
}
}