内联模板:1:1由以下原因引起:self.context.onSubmit不是获取错误角度2的函数

时间:2017-09-13 09:17:30

标签: angular angular2-template

提交表单时收到错误。

login.component.html:

<div class="col-xs-offset-1 col-xs-10 col-sm-offset-2 col-sm-8 col-md-offset-3 col-md-6">
    <form #loginForm="ngForm" (ngSubmit)="onSubmit(loginForm.value)">
    <div class="form-group">
            <label>Username:</label>
            <input type="text" class="user name" placeholder="Enter user name" name="username" [(ngModel)]="userName"/>
        </div>
        <div class="form-group">
            <label>Password:</label>
            <input type="password" class="password" placeholder="Enter password" name="password" [(ngModel)]="password"/>
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-info" [disabled]="!loginForm.valid">Submit</button>
        </div>
    </form>
        <div *ngIf="errorMessage" class="alert alert-danger">
        <strong>Login error!</strong> Invalid credentails.
    </div>
</div>

login.component.ts:

export class LoginComponent {

  loginForm:FormGroup;
  private sub:any
  userName:string;
  password:string;

  errorMessage: string;

  constructor(private loginService:LoginService,private router:Router) { }

    onSubmit(value:any){
      console.log('form submit clicked');
    console.log(this.userName,this.password);

    this.loginService.login(this.userName,this.password).subscribe(data=>{
      console.log(data);

    },error =>  this.errorMessage = <any>error);


  }

}

我尝试了所有可能的方法。 此angular 2 on from submit error self.context.onSubmit is not a function链接也无法解决我的问题。 请各位调查一下。

0 个答案:

没有答案