2013-07-31 2 views
0

я хочу прочитать данные с JSon $ ресурса

, но здесь есть одна ошибка «JsonService не определен»

вот мой код

<div ng-controller="Test2Ctrl"> 
<accordion close-others="oneAtATime"> 
<accordion-group heading="Static Header"> 
    This content is straight in the template. 
</accordion-group> 
<accordion-group heading="{{group.title}}" ng-repeat="group in groups"> 
    {{group.content}} 
</accordion-group> 
<accordion-group heading="Dynamic Body Content"> 
    <p>The body of the accordion group grows to fit the contents</p> 
    <button class="btn btn-small" ng-click="addItem()">Add Item</button> 
    <div ng-repeat="item in items">{{item}}</div> 
</accordion-group> 

'use strict'; 
angular.module('jsonService', ['ngResource']) 
.factory('JsonService', function($resource) { 
return $resource('data/data.json'); }); 



'use strict'; 
angular.module('elnApp') 
.controller('Test2Ctrl', function ($scope) { 
    $scope.oneAtATime = true; 

JsonService.get(function(data){ 
    $scope.title = data.title; 
    $scope.content = data.content; 
}); 

Я так растерялся, пожалуйста, помогите

ответ

3

Вы не вводите JsonService в контроллер, вы должны изменить свой код, как показано ниже.

angular.module('elnApp') 
.controller('Test2Ctrl', function ($scope,JsonService) { 
    $scope.oneAtATime = true; 

JsonService.get(function(data){ 
    $scope.title = data.title; 
    $scope.content = data.content; 
}); 
+0

благодарит за вашу помощь – user2473037

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