It is quite odd, once i select one of the items, it shows another item’s detail and only the first one works, the second, third and the rest did not. I think it might do with the jobId problem (index Id) but i am unsure.
.controller('JobsCtrl', function($scope, Jobs, $http) {
// Get all posts
$scope.jobs = Jobs.all();
// Our form data for creating a new post with ng-model
// $scope.postData = {};
//$scope.newPost = function() {
// var post = new Post($scope.postData);
// post.$save();
// }
// Refresher
$scope.doRefresh = function() {
$http.get('http://www.mydomain.com/api/v1/jobs')
.success(function(newJobs) {
$scope.jobs = newJobs;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
};
})
.controller('JobCtrl', function($scope, $stateParams, Jobs) {
$scope.job = Jobs.get($stateParams.jobId);
});
When i use:
var jobs = [
{ title: 'Systems Administrator', 'id': 0, min_salary: '1500', max_salary: '2000', city: 'Kota Bharu', state: 'Kelantan' },
{ title: 'Computer Engineer', 'id': 1, min_salary: '1500', max_salary: '2000', city: 'Kota Bharu', state: 'Kelantan' }];
it works fine. Or can it be because of my JSON from the server? The Id doesn’t start with 0 and it random.
Thank you so very much for giving me the angular stuff… i will need it for some stuff.
EDIT
I found out that the code above in codepen uses an PlaylistId which is not random (starts with 0, then 1, 2, 3) but on the production the Id will be random and the code in the above codepen will not work under these circumstances.
ie:
var jobs = [
{ title: 'Systems Administrator', 'id': 2, min_salary: '1500', max_salary: '2000', city: 'Kota Bharu', state: 'Kelantan' },
{ title: 'Systems Administrator', 'id': 3, min_salary: '1500', max_salary: '2000', city: 'Kota Bharu', state: 'Kelantan' },
{ title: 'Computer Engineer', 'id': 9, min_salary: '1500', max_salary: '2000', city: 'Kota Bharu', state: 'Kelantan' }];
will have the data messed up.