With the following code snipped in angular2. the url is working beginning given as aspected. If i run processTab without running it through chrome.tabs.query's asynchronous callback. it works perfectly but if i run it within the callback. the value is being passed to the processTab function but it is not working properly.
Not Working**
randomFunction() {
var self = this,
curl:string;
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
// self.updateUrl = tab.url.replace(/.*?:\/\//g, "")
curl = tabs[0].url.replace(/.*?:\/\//g, "").replace(/\/$/, "");
self.processTab(curl);
});
}
processTab(url:string) {
this.listService.getData(url)
.subscribe(
data => this.data = data,
error => this.errorMessage = <any>error);
console.log("the url: " + url);
}
Working:
randomFunction() {
this.processTab("www.whateverurl.com");
}
processTab(url:string) {
this.listService.getData(url)
.subscribe(
data => this.data = data,
error => this.errorMessage = <any>error);
console.log("the url: " + url);
}
but the value is being passed to processTab in both instances.