Skip to content

Instantly share code, notes, and snippets.

@rajaramtt
Last active February 18, 2019 17:44
Show Gist options
  • Save rajaramtt/34d55af7f3d1d9d26eecdf98ff8a68bf to your computer and use it in GitHub Desktop.
Save rajaramtt/34d55af7f3d1d9d26eecdf98ff8a68bf to your computer and use it in GitHub Desktop.
Local References and ViewChild decarator in Angular
// <input type="text" class="form-control" trim #giftName />
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
export class UserComponent implements OnInit {
userNickName: String = '';
..
onAddGift(giftName: HTMLInputElement) {
this.userGiftName = giftName.value;
..
..
}
export class UserComponent implements OnInit {
@ViewChild('nickName') nickName : ElementRef;
userNickName: String = '';
..
onAddGift(nickName: HTMLInputElement) {
..
this.userNickName = nickName.nativeElement.value;
..
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment