Here is a snippet of my controller code:
angular.module('app.controllers', [])
.controller('rServationCtrl', function($scope) {
})
.controller('voitureCtrl',['$scope' ,'Voiture', function($scope,Voiture) {
$scope.VoituresData = Voiture.getVoituresData();
console.log($scope.VoituresData);
}])
And this represents my service implementation:
angular.module('app.services', [])
.factory('Voiture', [function(){
var VoituresData = JSON.parse([
{
"idVoiture": 123,
"numChassee": 1234,
"numImmatricule": "120",
"kilometrage": 0,
"photo": null,
"couleur": "Noire",
"nbPlaces": 5,
"categorie": "sport",
"date_assurance": "2016-07-28T00:00:00.000Z",
"date_vignette": "2016-07-28T00:00:00.000Z",
"date_visite_tecknique": "2016-06-30T00:00:00.000Z",
"prixLocation": 1500,
"disponibilite": true,
"Modele_idModele": 123457,
"Modele": {
"idModele": 123457,
"nom": "A4",
"marque": "Audi",
"carburant": "Essence",
"puissance": 4,
"prixGPS": 25,
"prixChaisse": 25,
"prixChauffeur": 25
}
}, {
"idVoiture": 150,
"numChassee": null,
"numImmatricule": null,
"kilometrage": 10000,
"photo": null,
"couleur": null,
"nbPlaces": null,
"categorie": "sport",
"date_assurance": "2016-06-17T00:00:00.000Z",
"date_vignette": "2016-06-24T00:00:00.000Z",
"date_visite_tecknique": "2016-03-26T00:00:00.000Z",
"prixLocation": null,
"disponibilite": null,
"Modele_idModele": 123456,
"Modele": {
"idModele": 123456,
"nom": " 508",
"marque": "PEUGEOT",
"carburant": "Essence",
"puissance": 4,
"prixGPS": 25,
"prixChaisse": 25,
"prixChauffeur": 25
}
}
]);
function getVoituresData (){
return VoituresData;
}
return{
getVoituresData : getVoituresData
};
}]);
Including the controller in the html view and all scripts in index.html results in an error being displayed in the console:
SyntaxError: Unexpected token o
at Object.parse (native)
at Object.<anonymous> ([http://localhost:8100/js/services.js:6:25)
at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:17)
at Object.enforcedReturnValue \[as $get\] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17615:37)
at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:17)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17580:37
at getService (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17721:39)
at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17753:13)
at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17770:27)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:22326:28(anonymous function) @ ionic.bundle.js:25642(anonymous function) @ ionic.bundle.js:22421Scope.$broadcast @ ionic.bundle.js:29479$state.transition.resolved.then.$state.transition @ ionic.bundle.js:49321processQueue @ ionic.bundle.js:27879(anonymous function) @ ionic.bundle.js:27895Scope.$eval @ ionic.bundle.js:29158Scope.$digest @ ionic.bundle.js:28969Scope.$apply @ ionic.bundle.js:29263(anonymous function) @ ionic.bundle.js:31030completeOutstandingRequest @ ionic.bundle.js:18706(anonymous function) @ ionic.bundle.js:18978][1]