我正在使用 Angular js,我在两个不同的 jsp 文件中编写了代码。显示两个不同的 View 。 如果我渲染单个 View ,它工作正常。但是如果我在同一页面上渲染两个 View ,则会出现此错误
错误:参数“UserCtrl”不是函数,未定义
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");
});
我尝试为模块指定不同的名称,但这对我来说也不起作用。感谢任何帮助。 谢谢!
最佳答案
成功了。这是由于 ng-app 变量,我已将它绑定(bind)到两个 jsp 页面上。所以现在我将它绑定(bind)到两个 jsp 的主体包装器上。
关于jquery - Angular js 找不到 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14689401/