我正在尝试嵌套控制器,我收到以下错误:错误:[ng:areq] Argument' MainController'不是一个功能,未定义。我搜索了,我播种了一个类似的问题,但答案不适用于我的情况。
_Layout.cshtml
<body ng-controller="MainController" layout="column">
<div>
<md-content flex >
<div>
<md-toolbar class="md-accent">
<div class="md-toolbar-tools">
</div>
</md-toolbar>
</div>
<md-content flex layout-align="center center">
<md-sidenav md-component-id="left" class="md-sidenav-left md-whiteframe-z2" layout="column" id="sideNav">
<section layout="column">
<md-button class="md-raised md-primary">
@Html.ActionLink("Admin", "Index", "Admin/Index", new { area = "" }, new { @class = "myButtons" })
</md-button>
</section>
</md-sidenav>
<md-button class="md-raised md-primary" ng-click="clickSide('left')">Show menu</md-button>
<md-content class="AppContainer">
@RenderBody()
</md-content>
</md-content>
<footer>
<div layout="row" layout-align="center center">
<h2>My Awesome Footer © @DateTime.Now.Year</h2>
</div>
</footer>
</md-content>
</div>
</body>
app.js(主控制器)
var MyApp = angular.module('MyApp', ['ngMaterial', 'ngMessages', 'ngRoute']);
MyApp.controller('MainController', function ($scope,$rootScope, $http, $filter, $mdDialog, $timeout, $mdSidenav, $window, $location) {
$scope.clickSide = function (dir) {
$mdSidenav(dir).toggle();
};
});
AdminController.js
angular.module('MyApp', ['ngMaterial', 'ngMessages'])
.controller('AdminController', function ($scope, $http, $filter, $mdDialog) {
$scope.test = "Hello";
});
答案 0 :(得分:4)
您无需在AdminController中再次声明模块,更改如下,
MyApp.controller('AdminController', function ($scope, $http, $filter, $mdDialog) {
$scope.test = "Hello";
});