2013-02-04 157 views
4

我正在使用角js,我写了两个不同的jsp files.showing两个不同的意见代码。 如果我渲染它的工作原理fine.but如果我呈现同一页上都看法我得到这个错误Angular js没有找到控制器?

单一视图

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"); 
}); 

我试图给模块不同的名称,但同样没有工作了me.any帮助表示赞赏。 谢谢!

回答

6

了它的工作。这是由于ng-app变量,我将它绑定到了两个jsp页面。所以现在我将它绑定到jsp的主体包装器。

4

我想你reintializing应用可变请尝试下面的代码

var App = App ||angular.module('module', []); 

工作小提琴是 http://jsfiddle.net/e6A5q/

+0

感谢您的回复,但问题是别的,在我的回答中描述了它。 –

+0

谢谢你。我在两个单独的文件中对应用程序进行了双重实例化。 – Trip