gpt4 book ai didi

javascript - 可折叠菜单不起作用 - 参数 'SidebarController' 不是函数,未定义

转载 作者:行者123 更新时间:2023-12-03 08:09:00 25 4
gpt4 key购买 nike

我正在用 Angular 制作一个可折叠菜单,但它似乎破坏了我网页的其余部分!我已将其隔离在我的 app.js 中的某个位置文件,它控制着一切。我收到标题中所述的错误:

Error: [ng:areq] Argument 'SidebarController' is not a function, got undefined.

'use strict';

(function() {

// Declare app level module which depends on views and components
angular.module('app', [
'ngRoute',
'app.view1',
'app.view2',
'app.version'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/view1'});
}]);

//Sidebar toggle
app.controller('SidebarController', function($scope) {

$scope.state = false;

$scope.toggleState = function() {
$scope.state = !$scope.state;
};

});

app.directive('sidebarDirective', function() {
return {
link : function(scope, element, attr) {
scope.$watch(attr.sidebarDirective, function(newVal) {
if(newVal)
{
element.addClass('show');
return;
}
element.removeClass('show');
});
}
};
});

}())

这是相关的 <div>包含侧边栏:

<div id="page-wrapper" ng-class="" ng-cloak>
<div id="sidebar-wrapper" ng-controller="SidebarController" class="sidebar" sidebar-directive="state">
<a id="navigation-toggle" ng-click="toggleState()">MENU</a>
<ul class="navigation">
<li class="navigation-items">
<a href="#/view1">Denon Settings</a>
</li>
<li class="navigation-items">
<a href="#/view2">Light Settings</a>
</li>
</ul>
</div>

发生什么事了?

最佳答案

我明白了!问题是我没有正确定义app。声明应为:

// Declare app level module which depends on views and components
var app = angular.module('app', [
'ngRoute',
'app.view1',
'app.view2',
'app.version'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/view1'});
}]);

关于javascript - 可折叠菜单不起作用 - 参数 'SidebarController' 不是函数,未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34231677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com