【发布时间】:2015-11-03 14:20:12
【问题描述】:
我正在尝试让 ui-router 工作,而且我已经非常接近了。好吧,我让它工作了,但我无法将它与我的控制器结合起来,然后我得到了错误。
我在控制台中收到此错误
Error: [ng:areq] Argument 'searchCtrl' is not a function, got undefined
searchCtrl.js
var myApp = angular.module('myApp')
.controller('searchCtrl', [
'$scope', '$http', function($scope, $http) {
$scope.search = function() {
var base = 'http://api.themoviedb.org/3';
var service = '/search/movie';
var apiKey = 'a8f7039633f2065942cd8a28d7cadad4&query='
var search = $scope.searchquery
var callback = 'JSON_CALLBACK'; // provided by angular.js
var url = base + service + '?api_key=' + apiKey + search + '&callback=' + callback;
$http.jsonp(url,{ cache: true}).
success(function (data, status, headers, config) {
if (status == 200) {
$scope.movieList = data.results;
console.log($scope.movieList)
} else {
console.error('Error happened while getting the movie list.')
}
}).
error(function (data, status, headers, config) {
console.error('Error happened while getting the movie list.')
});
}
}
]);
我的 searchModule.js
var app = angular.module('movieseat', ['ui.router']).config([
'$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/state1');
return $stateProvider.state('state1', {
url: '/state1',
templateUrl: 'assets/angular-app/templates/state1.html'
});
}
]);
还有我的 app.js.coffee
@app = angular.module('movieseat', []);
@myApp = angular.module('myApp',[]);
# for compatibility with Rails CSRF protection
@app.config([
'$httpProvider', ($httpProvider)->
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
])
@app.run(->
console.log 'angular app running'
)
This might be the same question 并且我尝试将另一个模块添加到我的 app.js.coffee 但它不起作用。
有人给点小费吗?
【问题讨论】:
-
你想在这里创建两个不同的模块吗?如果答案是肯定的,那么将 myApp 模块注入到 movieseat 中。您在此处与模板绑定哪个模块?
-
@SatyamKoyani 我不认为我想要 2 个模块。
searchCtrl.js是一个控制器,它允许用户进行搜索操作。searchModule是一个包含模板的模块。所以也许我在searchCtrl.js中声明一个模块是错误的?
标签: angularjs angular-ui-router