drd2551 2016-12-30 13:51
浏览 84
已采纳

错误:[ng:areq]参数'SidebarController'不是函数,未定义

I have two problems with my demo:

Error: [ng:areq] Argument 'SidebarController' is not a function, got undefined http://errors.angularjs.org/1.2.26/ng/areq?p0=SidebarController&p1=not%20aNaNunction%2C%20got%20undefined

And, currently when I click on "instalaciones" or "Matrices" it opens or closes that individual menu.

However, I would like it to open the clicked item but close all other open items.

my html is:

<link href="modules/matrix/CSS/style.css" rel="stylesheet" />
<script src="modules/matrix/controllers/sidebarnav.js"></script>
<script src="bower_components/angular/angular.js" data-require="angular.js@1.3.15" data-semver="1.3.15"></script>

<div class="container" >
    <div class="row matrix-view">
        <div class="container-sidebar" ng-app>
            <div ng-controller="SidebarController">
                <div class="sidebarnav" sidebar-directive="state">
                    <a class="vertical-text" href="#" id="navigation-toggle"     ng-click="toggleState()">Instalaciones</a>
                <ul class="navigation">
                        <li>items</li>
                    </ul>
                </div>
            </div>
            <div ng-controller="SidebarController2">
                <div class="sidebarnav" sidebar-directive="state">
                    <a class="vertical-text" href="#" id="navigation-    toggle2" ng-click="toggleState()">Matrices</a>
                    <ul class="navigation">
                        <li>item</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="col-xs-9 grid">
            <grid></grid>
        </div>
    </div>
</div>

my Angularjs is:

/* global angular */
(function () {
    var app = angular.module('app',[]);
    app.controller('SidebarController', function ($scope){
        $scope.state = false;
        $scope.toggleState = function() {
                $scope.state = !$scope.state;
        };
    });
    app.controller('SidebarController2', 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');
                        });
                }
        };
    });
}())

and my css is:

body {
    font-family : arial;
}

.sidebarnav {
    position : absolute;
    top : 0;
    left : -160px;
    transition : 100ms left;
}

#navigation-toggle {
    position: absolute;
    left: 165px;
    margin-top: 5px;

}
#navigation-toggle2 {
    position: absolute;
    left: 165px;
    margin-top: 100px;
}

.show{
    left : 0;
}
.show a{
        left: 0px !important;
}
.show ul{
        left: 0px !important;
}

.navigation{
        list-style : none;
        padding : 0;
        margin : 0 0 0 20px;
}
.navigation-items{
    display : block;
    background-color : #e01212;
    color : white; 
    line-height : 2em;
    text-decoration : none;
    padding : 10px 30px;
    width : 100px;
}
.navigation-items a:hover{
    background-color : #222;
}

.vertical-text {
    display: inline-block;
    transform: rotate(90deg);
    transform-origin: left top 0;
    float: left;
    margin-left: 15px;
}

Can you please help me identify the problem?

  • 写回答

2条回答 默认 最新

  • dqjgf0982 2016-12-30 15:27
    关注

    This assigns the root element of the application to the div element

    <div class="container-sidebar" ng-app>
    

    Instead, you will want to assign the root element of the application to the "app" module you defined in your js, like this:

    <div class="container-sidebar" ng-app="app">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制