angular-fullstack/generator-angular-fullstack

Incorrect usage of Promise and safeCb in code using auth.service.ts (canary)

Open

#2 682 ouverte le 30 déc. 2017

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)JavaScript (1 268 forks)batch import
good first issue

Métriques du dépôt

Stars
 (6 134 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

  • I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 5.0.0-beta.3
Node v8.9.3
npm 5.6.0
Operating System Ubuntu 16.04
Item Answer
Transpiler TypeScript
Markup HTML
CSS SCSS
Router ui-router
Client Tests Mocha
DB MongoDB
Auth Y

Example

auth.service.ts

    changePassword(oldPassword, newPassword, callback) {
        return this.UserService.changePassword({id: this.currentUser._id}, oldPassword, newPassword)
            .toPromise()
            .then(() => {console.log("success"); safeCb(callback)(null)})
            .catch(err => {console.log("error"); safeCb(callback)(err)});
    }

Then in settings.component.ts you do:

  changePassword(): void {
    this.submitted = true;
    return this.AuthService.changePassword(this.oldPassword, this.password)
      .then(() => {
        // success message
      })
      .catch(err => {
        // incorrect password message
      });
  }

Here // success message is always displayed because safeCb returns undefined.

Guide contributeur