1

I realized that I can make sure of Promise.resolve to convert an Angular JS $q.defer() logic. However, I got the following problem:

Original Angular JS:

service.validValues = function(id,name) {
    var deferred = $q.defer();
    $q.all([service.check_id(id), service.check_name(name)]).then(
        function(student){
            service.validStud(student[0], student[1]).then(function(valid) {
                deferred.resolve(valid);
            });
        });
    return deferred.promise;
};

my code:

validValues(id, name) {
    let deferr = new Promise(deferred);
    function deferred(resolve, reject) {
        Observable.forkJoin([this.check_id(id), this.check_name(name)]).subscribe((student) => {
        this.validStud(student[0], student[1]).then(function(valid) {
            resolve(valid);
            });
        });
     return deferr;
}

Is it wrong? Cause I never got the valid values. Although the code can be compiled but I always got "undefined" for 'deferr' when I do a console.log.

Thank you so much!

James.C
  • 23
  • 1
  • 6
  • Possible duplicae of https://stackoverflow.com/questions/37719306/whats-the-equivalent-of-angulars-q-in-angular2 – Anuradha Gunasekara Jun 18 '18 at 16:22
  • Sorry, I am not quite understand, the link you mentioned is talking about .when, but in my case it is .then, are they the same? Thank you. – James.C Jun 19 '18 at 00:35

0 Answers0