Ah! I've encountered this before!

Don't wrap your $scope.gridOptions = { data: 'myData' }; inside the $http 
call. I'm not sure if the next step is required but, ensure you initialize 
$scope.myData outside of the $http call first.

On Friday, 28 February 2014 18:31:22 UTC+8, Kévin Ribot wrote:
>
> Hello,
>
> I want to recover data from a JSON file and display them in <div> with 
> ng-grid property.
>
>
> *My file JSON* :
>
>
>
> {
>     "prestataires":[
>         {
>             "code" : "001",
>             "nom" : "MIEJERON",
>             "prenom" : "Fabrice",
>             "mail" : "[email protected] <javascript:>",
>             "tel" : "0606060606"
>         },
>         {
>             "code" : "002",
>             "nom" : "MIEJERON",
>             "prenom" : "Maurice",
>             "mail" : "[email protected] <javascript:>",
>             "tel" : "0606060606"
>         }
>     ]
>  
> }
>
>
> *My controller : *
>
> 'use strict';
>  
> var myApp = angular.module('regiePub');
> myApp.controller('PrestaCtrl', function ($scope, $http, $templateCache) {
>     $scope.awesomeThings = [
>         'HTML5 Boilerplate',
>         'AngularJS',
>         'Karma'
>     ];
>  
>  
> //        Récupération de données JSON (liste des prestataires)
>     $scope.method = 'GET';
>     $scope.url = '/scripts/json/prestataire.json';
>     $scope.code = null;
>     $scope.response = null;
>  
>     $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
>         //en cas de succès
>         success(function (data, status) {
>             $scope.status = status;
>             $scope.myData = data.prestataires; //liste des prestataires 
> contenus dans le tableau
>             $scope.gridOptions = { data: 'myData' };
>         }).
>         //en cas d'erreur
>         error(function (data, status) {
>             $scope.myData = data || "Erreur dans la requête HTTP.";
>             $scope.status = status;
>         });
>  
>  
> });
>
>
>
> *My view :*
>
>  <div class="gridStyle" ng-grid="gridOptions"></div>
>
>
>
> I get an error :
>
>
>
> Error: p is undefined
>
>
> d.compile/<.pre@
> http://myURL/bower_components/ng-grid/ng-grid-2.0.7.min.js:2
> nodeLinkFn@http://myURL/bower_components/angular/angular.js:6193
> compositeLinkFn@http://myURL/bower_components/angular/angular.js:5622
> compositeLinkFn@http://myURL/bower_components/angular/angular.js:5625
> compositeLinkFn@http://myURL/bower_components/angular/angular.js:5625
> nodeLinkFn@http://myURL/bower_components/angular/angular.js:6206
> compositeLinkFn@http://myURL/bower_components/angular/angular.js:5622
> publicLinkFn@http://myURL/bower_components/angular/angular.js:5527
> ngViewFillContentFactory/<.link@
> http://myURL/bower_components/angular-route/angular-route.js:905
> nodeLinkFn@http://myURL/bower_components/angular/angular.js:6213
> compositeLinkFn@http://myURL/bower_components/angular/angular.js:5622
> publicLinkFn@http://myURL/bower_components/angular/angular.js:5527
> boundTranscludeFn@http://myURL/bower_components/angular/angular.js:5641
> controllersBoundTransclude@
> http://myURL/bower_components/angular/angular.js:6233
> update@http://myURL/bower_components/angular-route/angular-route.js:855
> $RootScopeProvider/this.$get</Scope.prototype.$broadcast@
> http://myURL/bower_components/angular/angular.js:12181
> $RouteProvider/this.$get</updateRoute/<@
> http://myURL/bower_components/angular-route/angular-route.js:556
> qFactory/defer/deferred.promise.then/wrappedCallback@
> http://myURL/bower_components/angular/angular.js:10905
> qFactory/defer/deferred.promise.then/wrappedCallback@
> http://myURL/bower_components/angular/angular.js:10905
> qFactory/ref/<.then/<@
> http://myURL/bower_components/angular/angular.js:10991
> $RootScopeProvider/this.$get</Scope.prototype.$eval@
> http://myURL/bower_components/angular/angular.js:11906
> $RootScopeProvider/this.$get</Scope.prototype.$digest@
> http://myURL/bower_components/angular/angular.js:11734
> $RootScopeProvider/this.$get</Scope.prototype.$apply@
> http://myURL/bower_components/angular/angular.js:12012
> done@http://myURL/bower_components/angular/angular.js:7818
> completeRequest@http://myURL/bower_components/angular/angular.js:7991
> createHttpBackend/</xhr.onreadystatechange@
> http://myURL/bower_components/angular/angular.js:7950
>
> <div class="gridStyle ng-scope" ng-grid="gridOptions">
>
>
>
>
> *It works when I use :*
>
> <div  ng-repeat="prestataire in myData"> {{prestataire.nom}}</div>
>
>
> Help me Please :)
>
>
>
> Kévin
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to