2017-08-12 63 views
1

我在启动我的应用程序时遇到了此错误。我在做什么错了? 我已经在我的模块中导入了FormsModule和ReactiveFormsModule包。 我采用了棱角分明2.4.9AngularJS 2:由于它不是“输入”的已知属性,因此无法绑定到'ngModel'

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}}</"): [email protected]: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> 
+0

该角的版本你正在努力基于myModel财产。你也可以发布的HTML? – JEMI

+0

我正在使用Angular 2.4.9 –

回答

0

我创建了一个相同版本的示例(2.4.9)的角度,它对我来说工作得很好。我想,你是不是你的声明组件

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

<input [(ngModel)]="myModel" placeholder=""> 

@Component({ 
    selector: 'app', 
    templateUrl: "src/app.html" 
}) 
export class App { 
myModel:string="test"; 
    constructor() { 

    } 
} 
相关问题