Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 2 http响应中的更改值不影响页面_Javascript_Angularjs_Http_Angular_Angular2 Http - Fatal编程技术网

Javascript Angular 2 http响应中的更改值不影响页面

Javascript 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

我对angular 2很陌生。我试图在收到http请求的响应后更改该值,该参数将在页面中使用。我不明白为什么即使控制台日志中的值已更改,它也不会影响页面

page.html
当您使用
功能
时,您将丢失
的当前
。您应该在可观察的
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';
        }
    );
}