Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 5基于先前表单控件的动态表单_Angular_Form Control - Fatal编程技术网

Angular 5基于先前表单控件的动态表单

Angular 5基于先前表单控件的动态表单,angular,form-control,Angular,Form Control,我们使用Angular 5,我们正在尝试设置一个动态表单,其中包含显示角色不是管理员时的选项。我正在使用ngIf,并尝试检查formcontrol中的角色。我显然没有做到这一点,我开始怀疑,如果不调用ts文件中的方法让组件设置变量,是否可以做到这一点 下面是表格的摘录 <div class="form-group"> <span>Role*</span> <select class="form-contro

我们使用Angular 5,我们正在尝试设置一个动态表单,其中包含显示角色不是管理员时的选项。我正在使用ngIf,并尝试检查formcontrol中的角色。我显然没有做到这一点,我开始怀疑,如果不调用ts文件中的方法让组件设置变量,是否可以做到这一点

下面是表格的摘录

<div class="form-group">
            <span>Role*</span>
            <select class="form-control" formControlName="role" id="Role">
                <option *ngFor="let role of roles" [ngValue]="role">
                    {{role.Description}}
                </option>
            </select>
        </div>
        <div *ngIf="addUserFrm.controls.role.Description != 'Admin'" class="form-group">
            <span>Centre*</span>
            <select class="form-control" formControlName="centre" id="Centre">
                <option *ngFor="let centre of centres" [ngValue]="centre">
                    {{centre.Description}}
                </option>
            </select>
        </div>
        <div class="form-group" *ngIf="addUserFrm.controls.role.Description != 'Admin'">
            <span>Infrastructure*</span>
            <select class="form-control" formControlName="infrastructure" id="Infrastructure">
                <option *ngFor="let infrastructure of infrastructures" [ngValue]="infrastructure">
                    {{infrastructure.Description}}
                </option>
            </select>
        </div> 

角色*
{{role.Description}}
中心*
{{center.Description}}
基础设施*
{{infrastructure.Description}
非常感谢您可以使用
get(path:Array | string):AbstractControl | null
,或更可读的,
formGroupName.get('formControlName')
函数以获取动态表单中的表单控件

因为您只包含了表单的一个摘录,所以我不能肯定这个片段会起作用,但您应该明白这一点

<div *ngIf="addUserFrm.get('role').value.Description != 'Admin'" class="form-group">