角度材料输入使用[(ngModel)]的双向数据绑定在生产模式下不起作用

问题描述 投票:1回答:2

我一直在研究Angular项目。一切都在localhost中工作,但是当我托管项目时,双向绑定不起作用。这是部分代码:

app.module.ts:

import { FormsModule , ReactiveFormsModule} from '@angular/forms';
import { MatInputModule } from '@angular/material/input';

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        MatInputModule
    ]
})

app.component.html:

<mat-form-field>
        <input matInput name="username" #username="ngModel" type="text" placeholder="User name"  [(ngModel)]="profile.username" required >
        <mat-error>This field is required</mat-error>
</mat-form-field>

此代码完全适用于localhost,但它不能在生产模式下工作。请问有谁可以帮助我吗?

angular angular-material2
2个回答
3
投票

你的代码:

NAME = “用户名”

纠正:

NAME = “profile.username”


2
投票

将Angular cli和节点版本更新为最新版本将解决此问题。它应该工作

© www.soinside.com 2019 - 2024. All rights reserved.