html - Passing Object in ng-repeat to another page to display its contents -
i working on project using mysql, angular, express, , node. have list of objects in ng-repeat , when click specific item pass clicked object page , show object's properties through angular.
here code:
html:
<div class = "panel panel-info" ng-repeat="job in job"> <div class = "panel-heading clickable"> <h1 class = "panel-title">{{job.title}}</h1> <span class = "pull-right"><i class = "glyphicon glyphicon-minus"></i></span> </div> <div class = "panel-body"> <!--this place students information placed nodejs--> <!--<p style = "text-decoration: underline"> job title <p>--> <p> {{job.description}} </p> <p> {{job.first_name}} {{job.last_name}}</p> <p> {{job.location}} </p> <br> <div class="form-group"> <div class=" col-sm-15"> <button onclick="location.href='jobpage.html';" type="submit" class="btn btn-default btn-block">apply</button> </div> </div> </div> </div>
controller:
soopcontrollers.controller("landingcontroller", function ($scope, $http){ $scope.formdata = {}; $http.get('/api/joblanding') .success(function(data){ $scope.job = data; console.log(data); }) .error(function(data){ console.log('error: ' + data); }); //i want function job , send page $scope.getjob = function(){ $http.post('/api/job', $scope.formdata) .success(function(data){ $scope.formdata = {}; $scope.users = data; //$location.redirect(); console.log(data); }) .error(function(data){ console.log('error: ' + data); }); }; });
angularjs applications work same way regular web sites when comes navigation. difference instead of sending request server go new url, router intercepts location change, , goes route. controller (or resolve function) of route gets needs display.
so, need in ng-repeat instead of button is
<a ng-href="#/job/{{ job.id }}">apply</a>
and need route mapped path /job/:jobid
.
in controller of route, you'll like
$http.get('/api/job/' + $routeparams.jobid).then(function(response) { $scope.job = response.data; });
Comments
Post a Comment