当前位置: 首页 > 知识库问答 >
问题:

未处理的promise拒绝:模板解析错误:无法绑定到'ng模型',因为它不是'input'[duplicate]的已知属性

翟博雅
2023-03-14

我总是得到错误不能绑定到'ng模型',因为它不是'input'的已知属性。如果我尝试使用这样的东西:

<div *ngIf="guide" class="form-group">
    <label for="guideName">Name: </label>
    <input class="form-control" name="guideName" [(ngModel)]="test" required id="guideName">

    <button (click)="saveGuide(guide)"></button>
</div>

我的app.module.ts如下所示:

import {NgModule} from "@angular/core";
import {routing} from "./app.routing";
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from "@angular/forms";

import {GuideModule} from "./guide/guide.module";

@NgModule({
    imports: [BrowserModule, FormsModule, routing, GuideModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})

export class AppModule {}
"dependencies": {
    ...
    "@angular/forms": "^2.1.2",
    ...
}
(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: 'app',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            "@angular/forms": "node_modules/@angular/forms/bundles/forms.umd.js",
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
            // other libraries
            'rxjs': 'npm:rxjs',
            'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

共有1个答案

谭泉
2023-03-14

之所以出现此错误,是因为guide-details.component.ts不是您导入formsmoduleappmodule的一部分(ngmodel指令是formsmodule的一部分)。您必须将formsmodule导入到声明guide-details.component.ts的模块中,或者将guide-details.component.ts移动到appmodule的声明中。

 类似资料: