【发布时间】:2021-12-11 16:29:16
【问题描述】:
考虑以下层次结构:
<app-component>
<university-component></university-component>
<highSchool-component></highSchool-component>
</app-component>
在打开的应用程序组件中显示的对话框组件(dialog-component)包含 2 个选项(大学和高中:
<form nz-form [nzLayout]="'inline'" [formGroup]="validateForm" (ngSubmit)="submitForm()">
<h3> Please select your academic level </h3>
<nz-form-control [nzErrorTip]="getErrorTip('studentLevel')">
<nz-radio-group [(ngModel)]="radioValue" formControlName="studentLevel" nzButtonStyle="solid" nzSize="small">
<input type="radio" name="radio3" id="university" (change)="setRouter(2)">
<label class="universite-label four col" nzValue="universite" for="universite">University</label>
<input type="radio" name="radio3" id="highSchool" (change)="setRouter(1)">
<label class="lycee-label four col" nzValue="lycee" for="lycee" >High School</label>
</nz-radio-group>
</nz-form-control>
<div>
<label nzType="flex" nzJustify="center" nzAlign="middle" nz-radio-button (click)="changeRoute()" mat-dialog-close >GO</label>
</div>
</form>
如果我选择大学,应用程序组件加载大学组件,如果我选择高中,应用程序组件加载 highSchool 组件,我该怎么做
【问题讨论】:
-
...不确定问题是否正确...您的组件中绑定了
radioValueprop (ngModel-) => 所以<app-componnet> <university-component *ngIf="radioValue === 'someValOfNzRadioGroupValue'></university-component> <highSchool-component *ngIf="radioValue === 'someOhterValOfNzRadioGroupValue'></highSchool-component>... -
如果它可以正常工作的魔法(使用带有 formControlName 的 mgModel)
-
@Vovan_Super 我尝试了这个解决方案,但没有奏效!因为包含 radiValue 的对话框是一个单独的组件
-
@НикитаСереда 是的,工作正常...ibb.co/XJWbbD5
标签: angular typescript angular8 angular-services angular-data