无法绑定到“ ngModel”,因为它不是“ input”的已知属性。 (“

时间:2019-05-27 10:35:15

标签: angular

注意:我已经在app.module组件中添加了FormModule,但是仍然出现错误

仅当我使用loadChildren时才会发生这种情况,但是如果我使用带有路径的简单组件,则它可以正常工作

<h2 class="page-header">Login</h2>
<form (submit)="onLoginSubmit()">
  <div class="form-group">
      <label>Username</label>
      <input type="text" [(ngModel)]="username" name="username" class="form-control">
    </div>
      <div class="form-group">
          <label>Password</label>
          <input type="password" [(ngModel)]="password" name="password" class="form-control">
        </div>
        <input type="submit" class="btn btn-primary" value="Login">
</form>

login.component.ts

export class LoginComponent implements OnInit {

  username= String;
  password= String;

  constructor(private authService: AuthService,
    private router: Router,
    private flashMessage: FlashMessagesService,) { }

  ngOnInit() {
  }
  onLoginSubmit(){
    const user={
    username: this.username,
    password: this.password,
    }

0 个答案:

没有答案