Angular Meteor | Accounts.forgotPassword | SOLVED


#1

Hello, thanks for your time. I have a issue, the console sendme this message:

Exception in delivering result of invoking ‘forgotPassword’: TypeError: Cannot set property ‘show’ of undefined
at Scope. (http://localhost:3000/app/app.js?hash=c774768ec5c741fe40437fd18895d8388894c7cf:2914:27)
at http://localhost:3000/packages/modules.js?hash=edad20900328283da29ba6ed89a77ee3d1a59640:35836:24
at MethodInvoker._callback (http://localhost:3000/packages/meteor.js?hash=ae8b8affa9680bf9720bd8f7fa112f13a62f71c3:1105:22)
at MethodInvoker.maybeInvokeCallback (http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:3557:12)
at MethodInvoker.receiveResult (http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:3577:10)
at Connection.livedata_result (http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:4742:9)
at onMessage (http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:3385:12)
at http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:2736:11
at Array.forEach (native)
at Function.
.each.
.forEach (http://localhost:3000/packages/underscore.js?hash=27b3d669b418de8577518760446467e6ff429b1e:149:11)

Some ideas that how can solve?
This is my code:

imports/api/components/recuperar/recuperar.html

<form>
  <input type="email" name="email" placeholder="Email Address" ng-model="recuperar.email">
  <button ng-click="recuperar.send()">Send</button>
</form>

imports/api/components/recuperar/recuperar.js

import angular        from 'angular';
import angularMeteor  from 'angular-meteor';

import { Accounts }   from 'meteor/accounts-base'
import { Meteor }     from 'meteor/meteor'

import                     './recuperar.html';

class Recuperar {
  constructor($scope, $reactive) {
    'ngInject';
    $reactive(this).attach($scope);
    this.email = '';
  }

  send(){
    Accounts.forgotPassword({email:this.email}, this.$bindToContext((err) => {
        this.answer.show = true;
        if (err) {
            this.answer.message = 'Error';
            this.answer.fontawesome = 'danger';
            console.log('This is the error:', err);
        } else {
            this.answer.message = 'Success';
            this.answer.fontawesome = 'success';
            console.log('This is the success');
        }
      })
    );
  }
}

const name = 'recuperar';

// create a module
export default angular
.module(name, [
  angularMeteor
])
.component(name, {
   templateUrl: `imports/ui/components/${name}/${name}.html`,
  controllerAs: name,
    controller: Recuperar
})
.config(config);

function config($stateProvider) {
  'ngInject';

  $stateProvider
    .state('inicio.recuperar', {
           url: '/recuperar',
      template: '<recuperar></recuperar>'
    });
}

#2

Sorry…
It was my error. I not was defined answer.
Sorry, I am very new in this.

The error was solve with this:

 this.answer = {
   show: false,
   message: '',
   fontawesome: ''
 }

I put it for someone that need help jajaja…
… I dont think so…