【问题标题】:Can't bind to 'ngModule' since it isn't a known property of 'input'. in angular 2 asp.net core无法绑定到“ngModule”,因为它不是“输入”的已知属性。在 Angular 2 asp.net 核心中
【发布时间】:2017-05-11 15:20:23
【问题描述】:

包.json

{
  "version": "1.0.0",
  "name": "asp.net",
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "@angular/upgrade": "2.0.0",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.27",
    "zone.js": "^0.6.23",
    "angular2-in-memory-web-api": "0.0.20"
  },
  "devDependencies": {
  }
}

这是 app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { LoginComponent } from "./Components/login.Component";


    @NgModule({
        imports: [BrowserModule, FormsModule],
        declarations: [LoginComponent],
        bootstrap: [LoginComponent]
    })
    export class AppModule { }

我已经在 app.module 中导入了 FormsModule,但我仍然面临这个问题。

这是 login.component.ts

import { Component } from '@angular/core';
@Component({
    selector: 'login-app',
    templateUrl: 'Home/partialLogin'
})
export class LoginComponent {
    email: string;
    password: string;
    constructor() {
        this.email = "erere@ada.com";
        this.password = "test anand";

    }

    login(event) {
        console.log(this.email);
        event.preventDefault();

    }

}

login.cshtml

 <div style="margin-bottom: 25px" class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                        <input type="text" class="form-control" name="email" [(ngModule)] ="email" placeholder="username or email">
                    </div>

我已经谷歌了它的解决方案。他们到处都提到要导入我已经添加的 formModule 但仍然面临问题。

请任何人都可以解决这个问题。

【问题讨论】:

  • 应该是ngModel 而不是ngModule

标签: javascript jquery angularjs angular asp.net-core


【解决方案1】:

应该是ngModel 而不是ngModule。阅读更多NgModel documentation

<input type="text" class="form-control" name="email" [(ngModel)]="email" placeholder="username or email">

【讨论】:

  • 该死的错字,浪费了我的几个小时
【解决方案2】:

试试这个

<input type="text" class="form-control" name="email" [(ngModel)]="email" placeholder="username or email">

您也可以单独尝试[ngModel],这称为属性绑定,但是当您使用[(ngModel)] 时,这是双向数据绑定

@NgModule 是 Angular2 的注解,它允许我们获取代码/组件包。

【讨论】:

  • 很高兴听到 :)
【解决方案3】:

我希望应该是ngModel,它包含输入字段的值

ngModule 不同于 angularjs 中的模块,后者用于将应用程序组织成功能块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-18
    • 2016-12-17
    • 2018-04-23
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    相关资源
    最近更新 更多