Hi guys!
Ionic noob here visiting the forums for the first time today. First of all, sorry if I’m posting in the wrong sub or if my question has already been answered. I tried looking for a solution but am resorting to the forums now. I am also aware that this question might be more AngularJS specific so go ahead and hate if that’s the case
I’ve been able to set up my controller with no problem but having my data in a seperate json file is causing some problems.
When I try to open a page which needs to pull data from the controller I get the following errors:
SyntaxError: Unexpected token }
at Object.parse (native)
at fromJson (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8764:14)
at defaults.defaults.transformResponse (http://localhost:8100/lib/ionic/js/ionic.bundle.js:15113:18)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:15061:12
at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:7950:18)
at transformData (http://localhost:8100/lib/ionic/js/ionic.bundle.js:15060:3)
at transformResponse (http://localhost:8100/lib/ionic/js/ionic.bundle.js:15754:17)
at wrappedCallback (http://localhost:8100/lib/ionic/js/ionic.bundle.js:19197:81)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:19283:26
at Scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20326:28)
This is the code in my Controllers.js
angular.module('starter.controllers', [])
.controller('DishesCtrl', function ($scope, $http){
$http.get('js/dishes.json').success(function(data) {
$scope.dishes = data;
})
})
.controller('DishCtrl', function($scope, $routeParams) {
$http.get('js/dishes.json').success(function(data) {
var dish = data.filter(function(entry){
return entry.title === $scope.title;
})[0];
console.log(dish);
})
});
And here’s my .json
[
{
"title": "beef",
"cat": 1,
"prep": "5 minutes",
"cook": "20 minutes",
"img": "/img/maindishes.jpg",
"description": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.",
},
{
"title": "chicken",
"cat": 2,
"prep": "5 minutes",
"cook": "20 minutes",
"img": "/img/paleo.jpg",
"description": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.",
},
]
I feel like I’m making a really silly mistake here (or going completely the wrong way).
Thanks a lot in advance and hopefully I’ll be around the forums more often
Cheers!
Steve