作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我收到以下错误:
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">×</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/
我是一名优秀的程序员,十分优秀!