In my word-cloud application I have 2 directives, a word cloud directive and table directive that when a word in the word cloud is selected, it notify to the table so the table will also select the correspond word. The word-cloud and the table communicate by promise which resides in the service, and I want to destroy the promise:
service code:
this.selectedDefferd = $q.defer();
this.selectedPromise = this.selectedDefferd.promise;
notifySelect(id)
{
this.selectedDefferd.notify({newData: this.data[id]});
}
setSelect(callBack) {
this.selectedPromise.then(null, null, callBack);
}
word cloud directive code :
d3.select(this).on("click", function (d) {
...
ctrl.wordService.notifySelect(d.id);
}
table directive
var selectCallback = $(".selected");
wordService.setSelect(selectCallback);
Thanks in advance,
Harel
With reject() you can reject a promise
this.selectedDefferd.reject('Rejected!');
The 2nd parameter of the promise is for the rejection.
promise.then(function(greeting) {
alert('Success: ' + greeting);
}, function(reason) {
alert('Failed: ' + reason);
}, function(update) {
alert('Got notification: ' + update);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.