绑定不适用于角材料按钮

时间:2021-02-08 16:30:12

标签: angular angular-material model-binding

我有以下带有材料工具栏的模板。 app.component.html

<mat-toolbar>        
 <span>My Application</span>
 <div class="spacer"></div>
   <a mat-raised-button ngDefaultControl [(ngModel)]="tabName" value="create" color="ascent" style="margin-right: 10px">Create</a>
   <a mat-raised-button ngDefaultControl [(ngModel)]="tabName" value="search" color="ascent" style="margin-right: 10px">Search</a>
   <a mat-raised-button ngDefaultControl [(ngModel)]="tabName" value="update" color="ascent" style="margin-right: 10px">Update</a>    
</mat-toolbar>
<div [ngSwitch]="tabName">                  
   <app-search *ngSwitchCase="'search'"></app-search>
   <app-update *ngSwitchCase="'update'"></app-update>
   <app-create *ngSwitchDefault></app-create>
</div>

app.component.ts

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

@Component({
  selector: 'app-track',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

   public tabName = '';
   constructor() { }

   ngOnInit(): void {
   }

}

默认情况下,它打开创建模板,因为默认条件指向创建组件。 但是当我单击“搜索”或“更新”按钮时,它不会用单击的模板替换创建模板。 我做错了什么吗。

0 个答案:

没有答案