2

this is my controller:

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 is my service:

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
};


}]);

and i include my controller in the html view and all script in index.html and i have this error 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]

1 Answer 1

1

Try to change JSON.parse() parameter. It should be string.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

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
    }
  }
]');
Sign up to request clarification or add additional context in comments.

2 Comments

i chage it but i have this error: Uncaught SyntaxError: Unexpected token ILLEGAL
thinks i fixed it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.