0

I have this code but it keeps giving me an error

app.controller('myController',["$scope", '$location', '$http', '$rootScope',function($scope, $location, $http, $rootScope){
    $scope.gridOptions1 = {
    paginationPageSize: 15,
    columnDefs: [
      { name: 'الاسم' },
      { name: 'الجنس' },
      { name: 'الشركة' }
    ]
  };
  $http.get('/data/mydata.json')
  .then(function (data) {
    $scope.gridOptions1.data = data;
  })

this is the error: and this here is my json file:

[
{
    "الاسم": "سمير",
    "العائلة": "سمراوي",
    "العمر": "32",
    "الجنس": "ذكر"
},
{
    "الاسم": "حمدان",
    "العائلة": "ابو حميد",
    "العمر": "20",
    "الجنس": "ذكر"
},
{
    "الاسم": "خالد",
    "العائلة": "خلدون",
    "العمر": "15",
    "الجنس": "ذكر"
},{

    "الاسم": "سمير",
    "العائلة": "سمراوي",
    "العمر": "32",
    "الجنس": "ذكر"
},
{
    "الاسم": "حمدان",
    "العائلة": "ابو حميد",
    "العمر": "20",
    "الجنس": "ذكر"
},
{
    "الاسم": "خالد",
    "العائلة": "خلدون",
    "العمر": "15",
    "الجنس": "ذكر"
},
{
    "الاسم": "سمير",
    "العائلة": "سمراوي",
    "العمر": "32",
    "الجنس": "ذكر"
},
{
    "الاسم": "حمدان",
    "العائلة": "ابو حميد",
    "العمر": "20",
    "الجنس": "ذكر"
},
{
    "الاسم": "خالد",
    "العائلة": "خلدون",
    "العمر": "15",
    "الجنس": "ذكر"
},
{
    "الاسم": "سمير",
    "العائلة": "سمراوي",
    "العمر": "32",
    "الجنس": "ذكر"
},
{
    "الاسم": "حمدان",
    "العائلة": "ابو حميد",
    "العمر": "20",
    "الجنس": "ذكر"
},
{
    "الاسم": "خالد",
    "العائلة": "خلدون",
    "العمر": "15",
    "الجنس": "ذكر"
},
{
    "الاسم": "سمير",
    "العائلة": "سمراوي",
    "العمر": "32",
    "الجنس": "ذكر"
},
{
    "الاسم": "حمدان",
    "العائلة": "ابو حميد",
    "العمر": "20",
    "الجنس": "ذكر"
},
{
    "الاسم": "خالد",
    "العائلة": "خلدون",
    "العمر": "15",
    "الجنس": "ذكر"
},
{
    "الاسم": "سمير",
    "العائلة": "سمراوي",
    "العمر": "32",
    "الجنس": "ذكر"
},
{
    "الاسم": "حمدان",
    "العائلة": "ابو حميد",
    "العمر": "20",
    "الجنس": "ذكر"
},
{
    "الاسم": "خالد",
    "العائلة": "خلدون",
    "العمر": "15",
    "الجنس": "ذكر"
}
];

the file is called mydata.json. 'pardon the language difference'. What I think my problem is is that I'm not using $http.get() function the right way. I'm not sure weather I can use $http.get() for local urls. Please help and thank you in advance

2
  • plnkr.co/edit/P0HQeO2rGerVquLrARSm?p=preview Commented Jul 4, 2017 at 8:47
  • Sorry but I tried you're solution to it and it still didn't work, it didn't change anything, I still have the same error, any other ideas? thanks for the help Commented Jul 4, 2017 at 9:42

2 Answers 2

1

remove the semicolon in the last line in your JSON file.

Also, data comes under data property. use data.data

$http.get('/mydata.json')
  .then(function (data.data) {
    $scope.gridOptions1.data = data.data;
  });
Sign up to request clarification or add additional context in comments.

1 Comment

When I use .then(function (data.data) it gives me an extra error:"Uncaught SyntaxError: Unexpected token ." and it doesn't solve the first one
1

you can find your required object in data.data try using error call back like this to catch the error

$http.get('/mydata.json')
  .then(function (data) {
    $scope.gridOptions1.data = data;
  },function(err){
    console.log(err);
});

6 Comments

I tried that but it only added a new error!! any other ideas on how I could solve this, thanks for the help (y)
what error did u get.? i got it alright when i tried. can us show the eroor
with pleasure: FileJS.js:187 Uncaught SyntaxError: Unexpected token .
can u give screenshots of the code?..and the error. what you are providing is not sufficient
I just edited the question because it's easier to add code and screenshots there so please go check it out
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.