我使用的是角度js,我在两个不同的jsp文件中编写了代码。显示了两个不同的视图。 如果我渲染单个视图它工作正常。但如果我在同一页面上渲染两个视图我得到了这个错误
Error: Argument 'UserCtrl' is not a function, got undefined
jsp中的js代码片段如下。
我的第一个jsp文件中的是
// Bootstrap the Application
var App = angular.module('module', []);
// Set up a controller and define a model
App.controller('UserCtrl', function($scope) {
$scope.user = {};
jQuery.get("<c:url value='${someUrl}'/>",
function(data) {
angular.element('#user_detail').scope().user = data;
angular.element('#user_detail').scope().$apply();
}, "json");
});
,第二个是
// Bootstrap the Application
var App = angular.module('module', []);
// Set up a controller and define a model
App.controller('ProfileCtrl', function($scope) {
$scope.profile = {};
jQuery.get("<c:url value='${someUrl}'/>",
function(data) {
angular.element('#profile').scope().profile = data;
angular.element('#profile').scope().$apply();
}, "json");
});
我尝试给模块提供不同的名称,但这对我来说也不起作用。非常感谢。 谢谢!
答案 0 :(得分:6)
让它奏效了。这是由于ng-app变量,我已经将它绑定在两个jsp页面上。所以现在我将它绑定到jsp的主体包装器。
答案 1 :(得分:4)
我认为你正在重新定位app变量请尝试下面的代码
var App = App ||angular.module('module', []);
工作小提琴是
http://jsfiddle.net/e6A5q/