Angular 步进器窗体引发ngmodel问题
我正在尝试将Angular 步进器窗体引发ngmodel问题,angular,angular-reactive-forms,Angular,Angular Reactive Forms,我正在尝试将表单持久化数据发送到后端API(我已经将json数据绑定到这个表单,并尝试发送到后端API),我已经创建了一个表单,如下所示(HTML/模板代码如下所示)。当我从一个表单到这个特定的表单(我在这里谈论的表单)时,它会在控制台中给我一些奇怪的错误消息 错误: > ERROR Error: If ngModel is used within a form tag, either the name > attribute must be set or the form >
表单
持久化数据发送到后端API
(我已经将json
数据绑定到这个表单
,并尝试发送到后端API
),我已经创建了一个表单
,如下所示(HTML/模板代码如下所示)。当我从一个表单
到这个特定的表单
(我在这里谈论的表单
)时,它会在控制台中给我一些奇怪的错误消息
错误:
> ERROR Error: If ngModel is used within a form tag, either the name
> attribute must be set or the form
> control must be defined as 'standalone' in ngModelOptions.
>
> Example 1: <input [(ngModel)]="person.firstName" name="first">
> Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">
>错误:如果在表单标记中使用ngModel,则名称
>必须设置属性,否则无法创建窗体
>控件必须在ngModelOptions中定义为“独立”。
>
>例1:
>例2:
为此,我在表单中添加了[ngModelOptions]=“{standalone:true}”。但我仍然得到了错误
<mat-card>
<section class="container-fluid with-maxwidth chapter">
<article class="article1">
<div class="box1211 box-default12">
<div class="box-body1">
<div class="box-body">
<form>
<div class="form-group row">
<label for="name" class="col-md-0 control-label"></label>
<div class="col-md-4">
<mat-radio-group class="example-radio-group" [(ngModel)]="project.genPolicy" [ngModelOptions]="{standalone: true}">Auto-Code Options
<br/>
<br/>
<mat-radio-button class="example-radio-button" *ngFor="let gen of genPolicies" color="primary" [value]="gen" [checked]="gen === 'Create'">
{{gen}}
</mat-radio-button>
</mat-radio-group>
</div>
<div class="col-md-8">
<div class="callout1 text-muted callout-info1">
<p>Auto-Code (automatic test coverage for your APIs).
<br/>Continuously generates 5-point test coverage (Quality, Security, DOS, Injections,
Data-Leak, Log-forging etc) for all project endpoints.
<br/>Requires repository credentials for code check-in.
</p>
</div>
</div>
</div>
<div class="form-group row" *ngIf="project.genPolicy === 'Create'">
<div class="col-md-12" *ngFor="let res of autoCodeConfig">
<div *ngIf='res.type === "anonymous_invalid"'>
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<b>Type - {{ res.type }}</b>
</mat-panel-title>
</mat-expansion-panel-header>
<mat-form-field>
<textarea matInput placeholder="Assertions" [(ngModel)]='res.assertions' rows="3" cols="150" [ngModelOptions]="{standalone: true}"></textarea>
</mat-form-field>
<br/>
<label>Severity</label>
<mat-radio-group class="example-radio-group" [(ngModel)]='res.severity' [ngModelOptions]="{standalone: true}">
<mat-radio-button color="primary" class="example-radio-button" *ngFor="let sev of severity" [value]="sev">
{{sev}}
</mat-radio-button>
</mat-radio-group>
</mat-expansion-panel>
</mat-accordion>
</div>
</div>
<div class="col-md-12" *ngFor="let res of autoCodeConfig">
<div *ngIf='res.type === "auth_invalid"'>
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<b>Type - {{ res.type }}</b>
</mat-panel-title>
</mat-expansion-panel-header>
<mat-form-field>
<textarea matInput placeholder="Assertions" [(ngModel)]='res.assertions' [ngModelOptions]="{standalone: true}"></textarea>
</mat-form-field>
<br/>
<label>Severity</label>
<mat-radio-group class="example-radio-group" [(ngModel)]='res.severity' [ngModelOptions]="{standalone: true}">
<mat-radio-button color="primary" class="example-radio-button" *ngFor="let sev of severity" [value]="sev">
{{sev}}
</mat-radio-button>
</mat-radio-group>
</mat-expansion-panel>
</mat-accordion>
</div>
</div>
<mat-card-actions>
<button color="primary" mat-raised-button matStepperNext class="nav-btn pull-right">Save & Next</button>
</mat-card-actions>
</form>
</div>
</div>
</div>
</article>
</section>
</mat-card>
自动编码选项
{{gen}
自动代码(API的自动测试覆盖率)。
连续生成5点测试覆盖率(质量、安全、DOS、注入、,
所有项目端点的数据泄漏、日志伪造等。
代码签入需要存储库凭据。
类型-{res.Type}
严重程度
{{sev}}
类型-{res.Type}
严重程度
{{sev}}
保存下一个(&N)
既然您没有将表单标记用于角度表单,为什么还要使用表单标记?@AJT_82它默认添加了一些样式/分组,并且使代码更易于使用read@mast3rd3mon当然,我明白。我非常微妙地(不相关地)尝试将OP推进到使用角度表单:D@AJT_82:我们可以不使用表单而将所有表单数据发送到backennapi吗?请建议。。