I am beginner angular 2
Here is my input
<input type="hidden" value={{date}} #myname/>
Here is my code
console.log(document.getElementById('myname')); It's return null
why?
Kindly Advise me,
Thanks
I am beginner angular 2
Here is my input
<input type="hidden" value={{date}} #myname/>
Here is my code
console.log(document.getElementById('myname')); It's return null
why?
Kindly Advise me,
Thanks
As you defined template variable, you can access that element using ViewChild decorator. document.getElementById will only work when element has id property with specific value in that id attribute.
@ViewChild('myname') myNameElem: any;
import {ElementRef} from '@angular/core';
@ViewChild('myname') el:ElementRef;
ngAfterViewInit()
{
//this.el.nativeElement.focus();
//this.el.nativeElement.value()
// And more
}