inline template:1:1 caused by: self.context.onSubmit is not a function getting error angular 2

跟風遠走 提交于 2020-01-06 06:06:41

问题


Getting error while submiting my form.

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);


  }

}

I tried all the possible ways . This angular 2 on from submit error self.context.onSubmit is not a function link also not solving my problem . Please guys look into this.

来源:https://stackoverflow.com/questions/46193540/inline-template11-caused-by-self-context-onsubmit-is-not-a-function-getting-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!