2017-10-25 11 views
0

私はAngular2で作業しています。最近、角度cliを再インストールした後にエラーに直面しています。 ReferenceError:SignupComponent.webpackJsonp.463.SignupComponent.ResgisterNewEmp(http://localhost:4200/main.bundle.js:644:5)at ...ReferenceError:投稿は評価時に定義されていません

のeval(eval at webpackJsonp.463.SignupComponent.ResgisterNewEmp( http://localhost:4200/main.bundle.js:644:5)、:1:1)でReferenceが定義されていません。
ResgisterNewEmp(employeeCreds) 
{ 

    this._empRegistrationService.regEmp(employeeCreds).subscribe(posts=>{ 

    this.result=posts;////===>(this.,result is " ", and posts is throwing error)//// 
    if(this.result =="201") 
     { 
      this._router.navigate(['Signin']); 
      console.log('reg service '+ this.result); 
     } 

    }); 

} 

Error screen shot here この問題についてお手伝いください。

+1

"posts"変数は明らかに定義されていません。 RegEmpメソッドをチェックして、なぜ値を取得していないのかを確認します。 –

+0

これはregEMpメソッドです。 regEmp(EmpReg){ let headers = new Headers({'Content-Type': 'application/json'}); let = new RequestOptions({ヘッダ:ヘッダ)}; let body = JSON.stringify(EmpReg); console.log( "サービス本体" +本体); var result = this.http.post( 'http:// localhost:9810/api/Values/Register'、body、options) .map(res => res.json());戻り値: ; } これはサービスからの戻り値です。 – Tinku

答えて

0

thisの変数が混在しています。

ResgisterNewEmp(employeeCreds) 
{ 
    var $this = this; 
    $this._empRegistrationService.regEmp(employeeCreds).subscribe(posts=>{ 
    $this.result=posts; 
    if($this.result =="201") 
    { 
     $this._router.navigate(['Signin']); 
     console.log('reg service '+ $this.result); 
    } 

    }); 
} 
関連する問題