Input in Angular 2


Inputs
To handle the user inputs on UX and associate some events like s clicking a link, pushing a button, and entering text raise DOM events . Using the events we perform some actions on Page. i.e. post back or change events for Save/Update

Types Of events
    User Defined(Custom)
          System Defined ($events)


Syntax and Code Snippet
User Defined
  import { Component } from '@angular/core';
@Component({
  selector: 'myapp',
 template: ‘<button (click)="ShowAlert()">Click me!</button>’
})
export class AppComponent
{
myInfo = '';
ShowAlert()
 {
  this.myInfo = 'Test Check!';
 }
}


HTML Body

<body>
<myapp>Loading Please wait ...</myapp>
</body>
Once clicking on UX for button associated function get called “ShowAlert()” which perform some actions . i.e shows the messages . Here “ShowAlert()” is user defined function we have created. Further we can handle the text and data to perform some actions. 

System Defined 

import { Component } from '@angular/core';

@Component({
selector: 'myapp',
template:'<input (keyup)="onKeyUpEvent($event)">'
<div>{{ enteredValues}}</div>
<button (click)="ShowAlert()">Click me!</button>’})

export class AppComponent
{
 enteredValues = '';
 onKeyUpEvent(event: KeyboardEvent)
{
this.enteredValues += event.target.value + ' | ';
 }

}


$event.target.value
Access the event values (input entered )


Input in Angular 2 Reviewed by Rupesh on 04:10 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.