2014-02-13 41 views
0

我加載我的意見,我app.js

// create the module and name it testApp 
var testApp = angular.module('testApp', ['ngRoute']); 

// configure our routes 
testApp.config(function($routeProvider) { 
    $routeProvider 

    // route for the contact page 
    .when('/contact', { 
     templateUrl : 'js/ng-app/views/contact.html', 
     controller : 'contactController' 
    }); 

    .when('/search', { 
     templateUrl : 'js/ng-app/views/search.html', 
     controller : 'searchController' 
    }); 

}); 

我的搜索部分看起來像這樣:

searchController.js

testApp.controller("searchController", function($scope, $http){ 

    $scope.apiKey = "97f25560b91ea3ad6c84e6f8c7677e4d"; 
    $scope.results = []; 
    $scope.filterText = null; 
    $scope.init = function() { 
     //API requires a start date 
     var today = new Date(); 
     //Create the date string and ensure leading zeros if required 
     var apiDate = today.getFullYear() + ("0" + (today.getMonth() + 1)).slice(-2) + "" + ("0" + today.getDate()).slice(-2); 
     $http.jsonp('http://api.trakt.tv/calendar/premieres.json/' + $scope.apiKey + '/' + apiDate + '/' + 30 + '/?callback=JSON_CALLBACK').success(function(data) { 
      //As we are getting our data from an external source, we need to format the data so we can use it to our desired affect 
      //For each day get all the episodes 
      angular.forEach(data, function(value, index){ 
       //The API stores the full date separately from each episode. Save it so we can use it later 
       var date = value.date; 
       //For each episodes add it to the results array 
       angular.forEach(value.episodes, function(tvshow, index){ 
        //Create a date string from the timestamp so we can filter on it based on user text input 
        tvshow.date = date; //Attach the full date to each episode 
        $scope.results.push(tvshow); 
       }); 
      }); 
     }).error(function(error) { 

     }); 
    }; 
}); 

但是我得到:

Module Error 
error in component $injector 
Failed to instantiate module testApp due to: 
Error: [$injector:nomod] http://errors.angularjs.org/1.2.8/$injector/nomod?p0=digi... 
    at Error (native) 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:6:449 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:20:260 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:21:262 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:29:175 
    at Array.forEach (native) 
    at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:7:274) 
    at e (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:29:115) 
    at $b (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:32:232) 
    at Zb.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:17:431 

我想這是因爲我使用ngRoute。但是,如何解決此問題而不刪除ngRoute

我很感謝您的回覆?

回答

1

ngRoute模塊(或角路由)不再與angular.js捆綁在一起,需要單獨包含。你記得這麼做嗎?

docs

$路線被用於深聯的URL的控制器和視圖(HTML 諧音)。它監視$ location.url(),並嘗試將路徑映射到現有路徑定義 。

需要安裝ngRoute模塊。

而且here是如何獲得angular-route.js信息的文檔頁面。

ngRoute被從angular 1.2.0版本移到它自己的模塊。從changelog

由於5599b55b,使用$路由的應用程序現在需要加載 角route.js文件並定義ngRoute模塊的依賴關係。