jquery - Angular js 找不到 Controller ?

标签 jquery angularjs

我正在使用 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/

相关文章:

javascript - 信息窗口 AngularJS 中的按钮

javascript - 带垂直滚动条的div滚动条 "main"

javascript - 使用 $.ajax 定位某个 PHP 函数

javascript - AngularJs + php 身份验证

javascript - PhpStorm 将现有变量标记为 "Unresolved Variable"

javascript - AngularJS - 如何仅对多个事件的组合采取行动

javascript - AngularJS promise 没有回调?

jquery - 在网站上隐藏动画

javascript - 悬停卡有更好的方法吗?

jquery - 如何配置 ajax select2 以使用条形码扫描仪