angular 2 / typescript : get hold of an element in the template -


does know how hold of element defined in component template? polymer makes easy $ , $$. wondering how go in angular 2.

take example tutorial:

import {component} '@angular/core'  @component({     selector:'display'     template:`      <input #myname(input)="updatename(myname.value)"/>      <p>my name : {{myname}}</p>     `  }) export class displaycomponent {     myname: string = "aman";     updatename(input: string) {         this.myname = input;     } } 

how catch hold of reference of 'p' or 'input' element within class definition?

you can handle dom element via elementref injecting component's constructor:

constructor(myelement: elementref) { ... } 

docs: https://angular.io/docs/ts/latest/api/core/index/elementref-class.html


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -