簡體   English   中英

角材料輸入[[ngModel)]的雙向數據綁定在生產模式下不起作用

[英]Angular Material input Two-way Data Binding with [(ngModel)] is not working in production mode

我一直在從事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上可以正常使用,但是在生產模式下不起作用。 請問有人可以幫助我嗎?

您的代碼:

NAME = “用戶名”

更正:

NAME = “profile.username”

將Angular cli和node版本都更新到最新版本將解決此問題。 它應該工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM