我有private变量constructor和public变量class.
我使用this关键字来引用这些变量和函数.
undefined如果我尝试在此函数中访问此变量,我会得到.
我是新手typescript,如何在此函数中访问此变量?
技术:Typescript,Angular 2,Angular 1.6.5,JavaScript
管理 - 公司settings.ts
import { Component } from '../../../../common/extentions/to-angular2';
import { Http } from '@angular/http';
export class AdminCompanySettings {
public company: any;
constructor(private $http: ng.IHttpService) {
//
}
this.company = "New company";
console.log("Prints all public variables", this); //prints all variables
var data = { url: www.google.com, data: { user: value } }
this.$http(data).then(function (response) {
console.log(response);
console.log(this.company); // undefined …Run Code Online (Sandbox Code Playgroud)