samedi 24 octobre 2015

Dynamic segment is not working in ember

I'm trying to have this kind of a route in my project where the last part is user ID. http://localhost:4200/profile/5621140ff60f6dee985b88aa

I need to display details of user that have the above ID only.But after creating following files i found that all the users are loaded to template. not only the user that have specific Id. Why is that??

router.js

Router.map(function() {

  this.resource('profile', { path: '/profile/:user_id' });

   });

route/profile.js

import Ember from 'ember';

export default Ember.Route.extend({

    model: function(params, transition) {

        return this.store.query("user", params.user_id);
    }

});

profile.hbs

<h2>Welcome user</h2>

{{#each item in model}}
{{item.firstName}}
{{/each}}

server.js

app.get('/api/profile', function(req,res) {
    UserModel.find({},function(err,docs) {
        if(err) {
            res.send({error:err});
        }
        else {
            res.send({user:docs});
        }
    });
});




Aucun commentaire:

Enregistrer un commentaire