尝试访问子页面中的控制器时,我遇到以下错误
angular.js:13236错误:[ng:areq]参数'systemInfoController'不是函数,得到字符串
我的路由设置如下。路由方面工作正常,以节省空间我没有包括整个.config
.state("admin", {
url: "/admin",
templateUrl: "/admin/sideMenu",
data: {
requiresLogin : true
}
})
.state("admin.systemInfo", {
url: "/systemInfo",
templateUrl: "/admin/systemInfo",
data: {
requiresLogin: true
}
})
sideMenu(父页面)模块定义如下
angular.module("Admin", ["systemInfo"]);
angular.module("Admin")
.controller("adminMenuController", ["User", "$http", function (User, $http) {
var admin = this;
this.menuOptions = [];
$http.get('someOtherUrl' + User.language)
.success(function (data) {
angular.forEach(data, function (url) {
admin.menuOptions.push(url);
});
});
}]);// end of controller
systemInfo(子页面)模块定义如下
angular.module("systemInfo", []);
angular.module("systemInfo")
.controller("systemInfoController", ["$http"], function ($http) {
$http.get('someUrl')
.success(function (data) {
alert(data);
});
});//end of controller
这是我引用父模块的方法,这很好用
<div class="row">
<div>
<div ng-controller="adminMenuController as menuCtrl" class="col-sm-3">
<div class="sidebar-nav">
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="visible-xs navbar-brand">Sidebar menu</span>
</div>
<div class="navbar-collapse collapse sidebar-navbar-collapse">
<ul class="nav navbar-nav">
<li ng-repeat="menuItem in menuCtrl.menuOptions">
<a href="{{menuItem.Path}}">{{menuItem.Label}}</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</div>
<div ui-view class="col-sm-9"></div>
我正在引用子模块控制器,如下所示
<div ng-controller="systemInfoController as sysInfCtrl">
Content Goes Here
</div>
我能够访问/ admin / systemInfo并查看正在呈现的“Content Goes Here”字符串,但错误消息仍然存在。任何帮助解决这个问题将不胜感激。
答案 0 :(得分:1)
您有错误:
.controller("systemInfoController", ["$http"], function ($http) {
您正在关闭错误位置的支架