gpt4 book ai didi

angular - 无法在 'setAttribute' : 'Element' is not a valid attribute name. Angular 4 上执行 ']'

转载 作者:太空狗 更新时间:2023-10-29 16:54:46 30 4
gpt4 key购买 nike

我收到以下错误:

Failed to execute 'setAttribute' on 'Element': ']' is not a valid attribute name.

我简单做了模型:

export interface ModalComponentModel {
username: string;
password: string;
password2: string;
description: string;
}

我在我的组件中使用了它:

组件:

model: ModalComponentModel;

然后我尝试在我的 html 文件中使用它:

    <div class="modal-header">
<h4 class="modal-title text-center">Edit Profile</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-2 col-md-offset-2">
<form class="form" role="form" (ngSubmit)="whatDoesThisFormDo()">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" id="username" placeholder="Your username"
[(ngModel)]="model.username">
</div>
<div class="form-group">
<label for="password1">Password</label>
<input type="password" class="form-control" name="password1" id="password1" placeholder="Your password"
[(ngModel)]="model.password">
</div>
<div class="form-group">
<label for="password2">Confirm Password</label>
<input type="password" class="form-control" name="password2" id="password2" placeholder="Your password"
[(ngModel)]="model.password2">
</div>
<div class="form-group">
<textarea rows="4" cols="50" placeholder="Description" [(ngModel)]="model.description"]></textarea>
</div>
<div class="row">
<div class="col-xs-1">
<button value="update" type="button" class="btn btn-primary pull-left">Update</button>
</div>
<div class="col-xs-1">
<button value="cancel" type="button" class="btn btn-primary pull-left">Cancel</button>
<div class="clear"></div>
</div>
</div>

</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="activeModal.close('Close click')">Close</button>
</div>

在我添加到模型之前它工作正常,完整的 HTML 已按要求在上面。

我也无法正确并排放置按钮。

最佳答案

[(ngModel)]="model.description"]//']' 被不必要地添加了

改成

[(ngModel)]="model.description"

不要用方括号括起来。

更新:

您可以根据需要初始化您的 model 变量,

model:ModalComponentModel=<ModalComponentModel>{};

model:ModalComponentModel=<ModalComponentModel>[];

关于angular - 无法在 'setAttribute' : 'Element' is not a valid attribute name. Angular 4 上执行 ']',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45802404/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com