NG Switch Example
NG Switch Example
Switchdemo.component.ts
@Component({
selector: 'app-switchdemo',
templateUrl: './switchdemo.component.html',
styleUrls: ['./switchdemo.component.css']
})
product:any = {
Price: 5000.67,
InStock: true,
Photo: 'assets/shoe.jpg',
};
viewName:string = 'details';
DisplayView(val:any) {
switch(val)
case 'details':
this.viewName='details';
break;
case 'preview':
this.viewName = 'preview';
break;
case 'description':
this.viewName = 'description';
break;
default:
this.viewName = 'home';
break;
SelectView(e:any)
if(e.target.name) {
this.DisplayView(e.target.name);
} else {
this.DisplayView(e.target.value)
counter:number = 0;
PreviousClick(){
this.counter--;
this.viewName = this.Views[this.counter];
NextClick(){
this.counter++;
this.viewName = this.Views[this.counter];
SwitchDemo.Component.html
<div class="container-fluid">
<div class="btn-group">
</div>
<div class="btn-group">
<option value="details">Details</option>
<option value="preview">Preview</option>
<option value="description">Description</option>
</select>
</div>
</div>
<div *ngSwitchCase="'details'">
<h3>Basic Details</h3>
<dl class="row">
<dt class="col-3">Name</dt>
<dd class="col-9">{{product.Name}}</dd>
<dt class="col-3">Price</dt>
<dd class="col-9">{{product.Price}}</dd>
<dt class="col-3">Stock</dt>
</dl>
</div>
<div *ngSwitchCase="'preview'">
<h3>Preview</h3>
</div>
<div *ngSwitchCase="'description'">
<h3>Description</h3>
<p>{{product.Description}}</p>
</div>
<div *ngSwitchDefault>
</div>
</div>
<div class="page-item">
</div>
<div class="page-item">
</div>
<div class="page-item">
</div>
<div class="page-item">
</div>
<div class="page-item">
</div>
</div>
</div>