角度材料$ mdSidenav错误

时间:2016-02-17 12:20:53

标签: javascript angularjs angular-material

我刚开始使用角度素材,所以我构建了一个带有工具栏,sidenav和内容的骨架页面。

然而,当我尝试使用$ mdSidenav的toggle()切换sidenav时,它会给我以下错误:

example.com/bot2

这是HTML:

TypeError: $mdSidenav is not a function

和JS:

<!DOCTYPE html>
<!--[if lt IE 7]>
<html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en" ng-app="myApp" class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>My AngularJS Sandbox</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="bower_components/angular-material/angular-material.min.css">
    <link rel="stylesheet" href="style.css">
</head>
<body ng-controller="mainCtrl" layout="row" layout-fill ng-cloak>


<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade
    your browser</a> to improve your experience.</p>
<![endif]-->
<md-sidenav id="sideNav" md-component-id="left" class="md-sidenav-left md-whiteframe-z2">
    <md-toolbar id="sideNav-bar" layout="row"></md-toolbar>
    <md-divider></md-divider>
</md-sidenav>

<div layout="column" flex layout-fill>
    <md-toolbar layout="row" id="topBar" layout-align="left center" layout-padding>
        <a class="fa-holders" ng-click="openSideNav('left')"><i class="fa fa-bars"></i></a>
        <span layout="column" ng-bind="currentTitle"></span>
    </md-toolbar>
    <md-content id="content_wrapper" flex layout="row"></md-content>
</div>


<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="bower_components/angular-animate/angular-animate.min.js"></script>
<script src="bower_components/angular-aria/angular-aria.min.js"></script>
<script src="bower_components/angular-messages/angular-messages.min.js"></script>
<script src="bower_components/angular-material/angular-material.min.js"></script>
<script src="app.js"></script>
</body>
</html>

这是angular material's documentation。我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

您忘了注入$mdSidenav

.controller('mainCtrl', ['$scope', '$mdSidenav', function ($scope, $mdSidenav) {
    ...
}])

https://docs.angularjs.org/guide/di