angular2に奇妙なエラーがあります。次のコードは正常に動作します。これです。 <servicename> angle2のエラー機能で利用できません
loginResult.subscribe(
(data) =>
this.response = data,
(err) =>
this._ajaxService.handleError(err, 'A string to summarize the activity')
);
次のコードは、プロパティhandleErrorが未定義であるとは言いません。これは、要求が失敗した場合にのみ発生します。
loginResult.subscribe(
function (response) {
this.response = response;
console.log(this.response);
},
function (error) {
this._ajaxService.handleError(error, 'A string to summarize the activity')
}
);
'function(){}'を使わない場合は、 '()=> {}'の代わりに矢印関数を使用してください。矢印関数は 'this'コンテキストを保持し、関数はそれを変更できます。 – Dinistro