我得到以下错误:

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;

然后我try 在我的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"

不要用方括号把它包起来.

Update:

您可以根据需要初始化model变量,如下所示:,

model:ModalComponentModel=<ModalComponentModel>{};

model:ModalComponentModel=<ModalComponentModel>[];

Angular相关问答推荐

带有服务依赖的Angular测试类

父母和子元素在17号角不保持同步

如何用ANGLE指令覆盖Html元素的数据绑定属性

AG网格Angular 快捷菜单调用函数

无效的ICU消息.缺少';}';|Angular material 拖放(&A)

在剑道UI网格中包装Excel导出的列

带独立零部件的TranslateLoader[Angular 16]

从Angular 前端访问ASP.NET Core 8 Web API时出现CORS错误

合并Cypress和Karma的代码覆盖率报告JSON文件不会产生正确的结果

SignalR:协商有效,但消息未发送(.NET/Angular)

相同的 Angular 代码在生产环境中停止工作

NgRx Effects 抛出类型错误,我不知道发生了什么

如何从表单组中禁用的表单控件中获取值?

无法读取 angular2 中未定义(…)的属性 push

Angular2 测试 - 按 ID 获取元素

等待多个promises完成

Angular2 + Jspm.io:使用类decorator 时需要反射元数据垫片

为什么用?模板绑定中的运算符?

No provider for Router?

包 '@angular/cli' 不是依赖项