jeudi 4 octobre 2018

How to pass Error Message to Route from a different Controller in Ember js

Let, I have two routes and two controllers namely login and signup If I signup successfully then I want to perform transition to the route login with a success message as parameter,

/app/signup/controller.js

import Controller from '@ember/controller';

export default Controller.extend({
    actions: {
        signup: function(){
            let _this = this;
            let successMessage = 'successfully registered';
            var credentials = this.getProperties('name','identification','password');
            let list = this.store.createRecord('user', {
                name: credentials.name,
                email: credentials.identification,
                password: credentials.password
            });
            list.save().then(function(){
                _this.transitionToRoute('login','successMessage');
            });
        }
    }
});

app/login/template.hbs

<body>
  
</body>

/app/router.js

import EmberRouter from '@ember/routing/router';
import config from './config/environment';

const Router = EmberRouter.extend({
  location: config.locationType,
  rootURL: config.rootURL
});
Router.map(function() {
  this.route('login');
  this.route('signup');
});

export default Router;




Aucun commentaire:

Enregistrer un commentaire