2015-10-11 2 views
1

Я использую угловой $ resource.query для извлечения json-данных через REST. Когда я вызываю метод запроса() запрос GET отправляется на сервер и успешно извлекает данные JSON:

{ 
    "_links" : { 
    "self" : { 
     "href" : "http://localhost:8080/competitors{?page,size,sort}", 
     "templated" : true 
    } 
    }, 
    "_embedded" : { 
    "competitors" : [ { 
     "name" : "sdfdfsdf", 
     "tagline" : null, 
     "url" : null, 
     "active" : true, 
     "itemId" : 4, 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/competitors/4" 
     } 
     } 
    }, { 
     "name" : "aaaaa", 
     "tagline" : null, 
     "url" : null, 
     "active" : true, 
     "itemId" : 12, 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/competitors/12" 
     } 
     } 
    } ] 
    }, 
    "page" : { 
    "size" : 20, 
    "totalElements" : 3, 
    "totalPages" : 1, 
    "number" : 0 
    } 
} 

, но затем сразу же бросает это Js ошибка:

TypeError: href is null 
consoleLog/<()angular.js (line 12477) 
$ExceptionHandlerProvider/this.$get</<()angular.js (line 9246) 
processQueue()angular.js (line 14753) 
scheduleProcessQueue/<()angular.js (line 14761) 
$RootScopeProvider/this.$get</Scope.prototype.$eval()angular.js (line 15989) 
$RootScopeProvider/this.$get</Scope.prototype.$digest()angular.js (line 15800) 
$RootScopeProvider/this.$get</Scope.prototype.$apply()angular.js (line 16097) 
done()angular.js (line 10546) 
completeRequest()angular.js (line 10744) 
requestLoaded()angular.js (line 10685) 


stackFrame.js (line 357) 

Вот соответствующая js code:

$scope.Competitor = $resource("/competitors/:id", {id: "@id"}); 

    $scope.listItems = function() { 
     var query = $scope.Competitor.query(); 
     query.$promise.then(
      function successCallback(data) { 
       $scope.competitors = data._embedded.competitors; 
      }, 
      function errorCallback(data) { 
       console.log('error:'); 
       console.dir(data); 
      } 
     ); 
    }; 

После ошибки функция errorCallback выполняется, но значение данных равно null.

Я попытался это с угловой 1.4.7 и угловой 1.2.27

Любая помощь будет принята с благодарностью. Благодарю.

+0

создайте демоверсию, которая воспроизводит это. Можно создать файл данных и использовать '$ resource' в [plunker] (http://plnkr.co/edit/?p=catalogue) – charlietfl

+4

Firebug скрывает истинную ошибку, когда вы видите: TypeError: href is null попробовать другой браузер или откройте инструменты разработчика firefox вместо firebug. Удивительно, но факт. – ahmeij

+0

У меня также есть такая ошибка. благодаря @ahmeij за его ответ. я пытаюсь с версией разработки firefox и ошибка ошибки более комплексна – AlainIb

ответ

0

В соответствии с просьбой в комментариях, вот мой комментарий в ответ:

Firebug заслоняет истинную ошибку, когда вы видите: TypeError: HREF является недействительным попробовать другой браузер или открыть инструменты разработчика Firefox вместо поджигатель ,

Смежные вопросы