There are a few ways to do it, but first you have to ask yourself what is
your plan for routes? In other words, even if you successfully get /job to
show the job you want, if the user hits refresh, the reference to the job
will be lost.
With that in mind, I would suggest using ng-route along with ng-view for
deep linking and use routeParams like when('/job/:jobId'). You would link
to /job/1234 instead of just /job and in $routParams you'd be able to see
the jobId in the controller which would allow you to load the job data
fresh from the database if the user came directly to that page or
refreshed.
If you do not want to use routing, or if it doesn't even matter what the
url path is, a simple approach would be to use ng-show/hide or ng-switch or
even ng-if to switch between the table view and the single job view. I can
expand on this if it doesn't make sense.
Lastly, the way you are currently headed is to use a service which can
maintain a reference to the selected job so that when you switch to the new
path (aha, you must already be using $routeProvider with ng-view!) your
single page controller can know what job to reference.
//example of last case where we will just use your existing Job service to
do it
app.controller('searchResultCtrl', function ($scope, $location, Job) {
.... all the other stuff...
$scope.getJob = function (job) { * //this is where i need help*
Job.selectedJob = job;
$location.path('/job');
}
}
//in the single view controller, inject Job service into it and just
reference the new property
$scope.job = Job.selectedJob;
On Tuesday, March 18, 2014 8:41:02 AM UTC-6, Rudy Sanchez wrote:
>
> I am working on a job posting website. i have been able to retrieve the
> jobs listing from the database and insert them in a table using angular
> repeat. I have each job displaying on the table with the properties: jobId,
> jobTitle, jobDescription, dateAdded, dateStarted. I would like to be able
> to click on the jobId for a specific job and redirect to another view that
> will display all of that one specific job details. I have tried different
> ways but i am completely lost. thanks in advance!
> *CONTROLLER*
> 'use strict';
> app.controller('searchResultCtrl', function ($scope, $location, Job) {
> //retrieve jobs from sql database
> $scope.jobArray = Job.query();
> $scope.job = {
> jobId: '',
> jobTitle: '',
> description: '',
> startDate: '',
> dateCreated: ''
> };
>
> $scope.maxSize = 5; //pagination settings
> $scope.currentPage = 1;
> $scope.totalItems = 0;
>
> $scope.jobId = '';
>
> *//retrieve job from job table and reroute to different view*
>
> $scope.getJob = function (job) { * //this is where i need help*
> $scope.job = job;
> $location.path('/job');
> }
> });
> *JOB LISTING VIEW*
>
> <tr ng-repeat="job in jobArray.slice(((currentPage-1)*maxSize),
> ((currentPage)*maxSize))track by $index">
> <td><a ng-click='getJob(job)'>{{job.jobId}}</a></td>
> <td>{{job.jobTitle}}</td>
> <td>{{job.description}}</td>
> <td>{{job.startDate}}</td>
> <td>{{job.dateCreated}}</td></tr>
>
> *NEW INDIVDUAL JOB VIEW*
>
> <h1>Title</h1><h2>{{job.jobTitle}}</h2><h3>Job
> Descrption:</h3>{{job.description}}<h3>Job Start
> Date</h3>{{job.startDate}}<h3>Date Created</h3>{{job.dateCreated}}<h3>Job
> Id</h3>{{job.jobId}}
>
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.