AngularJS 2:无法绑定到'ngModel',因为它不是'input'的已知属性

时间:2017-08-12 23:19:46

标签: angular typescript

我在推送应用程序时遇到此错误。我弄错了什么? 我已经在我的模块中导入了FormsModule和ReactiveFormsModule包。 我正在使用Angular 2.4.9

app.module.ts:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { AppComponent }   from './app.component';
import { PainelComponent } from './painel/painel.component';

import { PainelModule } from './painel/painel.module';
import { SidebarModule } from './sidebar/sidebar.module';
import { FooterModule } from './shared/footer/footer.module';
import { NavbarModule} from './shared/navbar/navbar.module';

import { HashLocationStrategy, LocationStrategy } from '@angular/common';

@NgModule({
    imports:      [
        BrowserModule,
        PainelModule,
        SidebarModule,
        NavbarModule,
        FooterModule,
        FormsModule,                               
        ReactiveFormsModule,      
        RouterModule.forRoot([])
    ],
    declarations: [ AppComponent, PainelComponent ],
    providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
    bootstrap:    [ AppComponent ]
})
export class AppModule { }

控制台显示以下内容:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. (""for="">RA <span class="star">*</span></label><input type="text" [ERROR ->][(ngModel)]="myModel" />{{myModel}}</"): AlunoComponent@10:51 ; Zone: <root> ; Task: Promise.then ; Value: 

app.component.ts

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';

@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html'
})

export class AppComponent implements OnInit{
    location: Location;
    constructor(location:Location) {
        this.location = location;
    }
    ngOnInit(){
        $.getScript('dashboard.js');
    }
    public isMaps(path){
        var titlee = this.location.prepareExternalUrl(this.location.path());
        titlee = titlee.slice( 1 );
        if(path === titlee){
            return true;
        }
        else {
            return false;
        }
    }
}

我正在尝试进行测试,因此HTML页面非常简单

HTML页面

<div class="form-group">
<label class="control-label" for="">RA </label>
<input type="text" [(ngModel)]="myModel" />{{myModel}}</div>

1 个答案:

答案 0 :(得分:0)

我创建了一个具有相同版本( 2.4.9 )角度的样本,它对我来说很好。我认为您未在组件上声明 myModel 属性

https://plnkr.co/edit/Hmq6bdXkeaK3HQ33WCXX?p=preview

measurement