ngIf

1)app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

2)app.component.ts

import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent
{
    title: string = 'ngIf Example' ;
    showMe: boolean;
}

3)app.component.html

<p> {{title}} </p>
<div class='panel panel-primary'>
    <div class='panel-heading'>
        <p>Simple example of ngIf </p> 
    </div>
   <div class="panel-body">
       <div class="row">
            Show <input type="checkbox" [(ngModel)] ="showMe"/>
       </div>
       <div class='row'>
            <div *ngIf="showMe">
                  ShowMe is checked                  
            </div>
            <div *ngIf="!showMe">
                  ShowMe is unchecked                  
            </div>
       </div>
    </div>
</div>

results matching ""

    No results matching ""