2015-08-30 41 views
-1

我收到此错误angularjs厂家售后服务错误

...([c,d,arguments]);return k}}if(!e)throw Error("No module: "+d);var b=[],c=[],j=a... 

谁能请在这个问题上提供帮助。

<div ng-app="app"> 
     <div ng-controller="booksCtrl"> 
      <div ng-repeat="book in allBooks"> 
       <ul> 
        <li>{{book.title}}</li> 
        <li>{{book.author}}</li> 
        <li>{{book.year}}</li> 
       </ul> 
      </div> 
     </div> 
    </div> 

..............................

(function(){ 

    angular.module('app').factory('dataService', dataService); 

    function dataService(){ 
     return { 
      getAllBooks : getAllBooks, 
     }; 

     function getAllBooks(){ 
      return[ 
       { 
        book_id:1, 
        title:"hari potter", 
        author:"J.K. Rowling", 
        year:2009 
       }, 
       { 
        book_id:2, 
        title:"The Cat in the Hat", 
        author : "DR. Seuss", 
        year : 1967 
       }, 
       { 
        book_id:3, 
        title:"Encyclopedia", 
        author : "Donald j Sobol", 
        year : 1940 
       } 
      ]; 

     }; 
    }; 



}()); 


(function(){ 

    angular.module('app').controller('booksCtrl', booksCtrl); 

    function booksCtrl($scope, dataService){ 
     $scope.allBooks = dataService.getAllBooks(); 
    } 

}()); 

回答

0

我想你还没有初始化模块应用。你必须使用语法初始化你的模块

angular.module('app', []) 

在任何一个js文件中。

(function(){ 

angular.module('app',[]).controller('booksCtrl', booksCtrl); 
function booksCtrl($scope, dataService){ 
$scope.allBooks = dataService.getAllBooks(); 
} 
}()); 

从官方文件https://docs.angularjs.org/guide/module

要注意的是使用angular.module( 'Mymodule中',[])将创建模块Mymodule中和覆盖任何现有的命名MyModule的模块。使用angular.module('myModule')来检索现有的模块。