Friday, June 24, 2016

Angular 2 Beginning using Component

Angular 2 Beginning using Component:

In beginning, open app.component.ts file and write the code in it.

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: `        <h1 (click)="onSelect()">Ashish Ginotra's</h1>        <p>Hello World!</p>        <h1 *ngIf="showDetail === true">This is {{contact.lastname}}</h1>        <input [(ngModel)]="contact.lastname" type="text">    `,
})
export class AppComponent {
    public contact = {firstname:"Ashish",lastname:"Ginotra"};
        public showDetail = false;
    onSelect(){
        this.showDetail = true;
    }
}

Add this code in your file and run

npm strat.

This will show the output.

Thanks

No comments:

Post a Comment