Javascript Angular 2 http响应中的更改值不影响页面
我对angular 2很陌生。我试图在收到http请求的响应后更改该值,该参数将在页面中使用。我不明白为什么即使控制台日志中的值已更改,它也不会影响页面 page.htmlJavascript Angular 2 http响应中的更改值不影响页面,javascript,angularjs,http,angular,angular2-http,Javascript,Angularjs,Http,Angular,Angular2 Http,我对angular 2很陌生。我试图在收到http请求的响应后更改该值,该参数将在页面中使用。我不明白为什么即使控制台日志中的值已更改,它也不会影响页面 page.html 当您使用功能时,您将丢失类的当前此。您应该在可观察的success和error功能中使用箭头功能函数(){}应该是()=>{} testMsg = 'before request'; enabled() { let body = JSON.parse(this._settingService.load(this.pa
当您使用
功能
时,您将丢失类
的当前此
。您应该在可观察的success
和error
功能中使用箭头功能<代码>函数(){}应该是()=>{}
testMsg = 'before request';
enabled() {
let body = JSON.parse(this._settingService.load(this.pageName));
let url = this._settingService.loadUrl(this.pageName);
this._sesService.getCarsRestful().subscribe(
//changed to arrow function
(response) => {
console.log("Success Response" + response);
this.test2 = response;
// this.showFrame = 'show';
// console.log(this.showFrame);
this.testMsg = 'after request';
console.log(this.testMsg);
},
//changed to arrow function
(error) => { console.log("Error happened" + error) },
//changed to arrow function
() => {
console.log("the subscription is completed");
// console.log(this.test2[0].name);
// this.showFrame = 'show';
}
);
}
当您使用
功能
时,您将丢失类
的当前此
。您应该在可观察的success
和error
功能中使用箭头功能<代码>函数(){}应该是()=>{}
testMsg = 'before request';
enabled() {
let body = JSON.parse(this._settingService.load(this.pageName));
let url = this._settingService.loadUrl(this.pageName);
this._sesService.getCarsRestful().subscribe(
//changed to arrow function
(response) => {
console.log("Success Response" + response);
this.test2 = response;
// this.showFrame = 'show';
// console.log(this.showFrame);
this.testMsg = 'after request';
console.log(this.testMsg);
},
//changed to arrow function
(error) => { console.log("Error happened" + error) },
//changed to arrow function
() => {
console.log("the subscription is completed");
// console.log(this.test2[0].name);
// this.showFrame = 'show';
}
);
}
testMsg = 'before request';
enabled() {
let body = JSON.parse(this._settingService.load(this.pageName));
let url = this._settingService.loadUrl(this.pageName);
this._sesService.getCarsRestful().subscribe(
//changed to arrow function
(response) => {
console.log("Success Response" + response);
this.test2 = response;
// this.showFrame = 'show';
// console.log(this.showFrame);
this.testMsg = 'after request';
console.log(this.testMsg);
},
//changed to arrow function
(error) => { console.log("Error happened" + error) },
//changed to arrow function
() => {
console.log("the subscription is completed");
// console.log(this.test2[0].name);
// this.showFrame = 'show';
}
);
}