angularjs - passing ng repeat objects from one controller to other -
this question has answer here:
hi displaying data using ng repeat
.
displaying 3 persons in template.. when click on 1 of them. want display in detail information of person... need make new controller , new template...but know 1 way pass 1 of unique parameter mobile no controller.. changes path having mobile number controller , template.using location.path().search()
.. in 2nd controller can request information again using 2nd parameter.. okay ??
i wanted pass whole persons data 1 controller other don't know how can it...
use service set selected person's information , access information using routeparam
user's unique id.
the code structure below
angular .module('app') .controller('parentcontroller', function (userservice) { $scope.onselect = function (user) { userservice.setcurrentuser(user); } }) .controller('childcontroller', function ($routeparams, userservice) { $scope.user = userservice.getcurrentuser($routeparams.userid); }) .factory('userservice', function () { var currentuser = {}; return { getcurrentuser: getcurrentuser, setcurrentuser: setcurrentuser }; function getcurrentuser () { return currentuser; } function setcurrentuser (user) { currentuser = user; } })
Comments
Post a Comment