我在父組件中有一個帶有來自Angular Material的單選按鈕的表單,我獲取單選按鈕的值并將它們發送到父組件,效果很好,但我需要根據用戶選擇顯示不同的內容但是不是我的代碼不起作用。我能做些什么?
我嘗試使用 *ngIf 但沒有成功。
代碼
uj5u.com熱心網友回復:
嘗試這個
在您的模板中:
<div [ngSwitch]="seasonSelected">
<div *ngSwitchCase="'Winter'">content for winter</div>
<div *ngSwitchCase="'Spring'">content for spring</div>
<div *ngSwitchCase="'Summer'">content for summer</div>
<div *ngSwitchCase="'Autumn'">content for autumn</div>
</div>
在您的 ts 檔案中:
@Component({
selector: 'radio-ng-model-example',
templateUrl: 'radio-ng-model-example.html',
styleUrls: ['radio-ng-model-example.css'],
})
export class RadioNgModelExample implements OnInit {
seasonSelected = '';
constructor() {}
ngOnInit(): void {}
editSeasonVisibility(seasonSelected: string) {
this.seasonSelected = seasonSelected;
alert(seasonSelected);
//this.test = seasonSelected === 'Winter' ? 'ok' : 'noOk';
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/507196.html
上一篇:用python去除SQL中的注釋
