I want to show the users info and make it editable in his profile page, 
using angular, node, and sequelize. Nothing really works so I would really 
appreciate some help!

my backend:

router.get('/:id', function(req, res, next){
   if(req.params.id==req.user.id)
     User.findOne({
      where: {
      id: req.params.id
     }
     }).then(function(user){
    res.send(user)
  })
   .catch(next);
 }
 else {
    res.status(401).send('Sorry');
  }

});

frontend angular

factory:

var baseUrl = '/api/users/';
var getData = res => res.data;

UserFactory.findUser=function(id){
   return $http.get(baseUrl + id)
    .then(getData)
    .then(function(user){
      return user;
   })
}

profile directive:

app.config(function ($stateProvider) {
  $stateProvider.state('profile', {
   url: '/profile/:userId',
   templateUrl: 'js/profile/profile.html',
   controller:'ProfileCtrl',
   resolve: {

     singleUser: function (UserFactory, $stateParams) {
        return UserFactory.findUser($stateParams.userId);
     },
    }
  });
});

profile controller:

app.controller('ProfileCtrl', function($scope,UserFactory, $log, singleUser){
   $scope.theUser = singleUser;

})

profile html (part of it)

<div>
<form>
    <input  ng-model = "theUser.firstName">{{theUser.firstName}}</input>
    <input  ng-model = "theUser.lastName">{{theUser.lastName}}</input>
    <input placeholder= 'Address' ng-model = "theUser..address"></input>
</div>
</form

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to