0

I want to return the value from Promise then to template function. I'm trying to pass by making promise from subscribe and then on completing promise return the answer.

How to do that, if i return any string in template function, it works fine

template: function (e: any) {
                    (function (e) {
                        return new Promise((resolve, reject) => {
                            let val: KeyValue<any> = new KeyValue<any>();
                            val.Key = m.field;
                            val.Value = e;
                            self.config.outGoingEvents.filter(p => p.Key == m.field)[0].Value.next(val);
                            self.config.inComingEvents.filter(p => p.Key == m.field)[0].Value.take(1).subscribe(m => {
                                resolve(m.Value);
                            });
                        }).then((resol: any) => {
                            debugger;
                            console.log(resol);
                            return resol;

                        });
                    })(e);
                }

I have even tried a single promise and it didnt work either.

template: function (e: any) {
     let a = (function() {
                            return new Promise((resolve, reject) => {
                                resolve("AAA");
                            })
                        }).bind(this);

                        a().then(pl => {
                            console.log(pl);
                            return pl;
                        });}
Shan Khan
  • 9,667
  • 17
  • 61
  • 111
  • http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-toPromise – cartant Dec 11 '17 at 18:43
  • if you are using toPromise with observables it is generally an indication that you have something wrong. Why are you using promises in this case and not using the observable directly? – Steverob2k Dec 11 '17 at 20:58
  • i am actually trying to return from subscribe, i tried putting return statement in subscribe directly but it didnt work, how i can return to template function from subscribe – Shan Khan Dec 12 '17 at 04:52

0 Answers0