我正在使用Angular 2和一個使用回調返回結果的Google Api編寫應用程序。Angular 2:如何將回調結果返回給組件?
我似乎無法得到結果返回到組件。 Typescript已經接管'this',我不確定如何從回調函數上下文返回Component的類上下文。
下面是基本示例代碼:
@Component({
selector: '...',
viewProviders: [...],
templateUrl: '...',
directives: [...],
providers: [...]
})
export class TestComponent {
new google.visualization.Query('...')
.send(function handleResponse(response : any){
let datatable = response.getDataTable();
...
results.push(item);
}
this.viewCollection = results; //this no longer refers to the TestComponent
});
...
}