我正在我的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
?
感谢您的回复?
答案 0 :(得分:1)