gpt4 book ai didi

javascript - Angular Material $mdSidenav 错误

转载 作者:行者123 更新时间:2023-11-30 12:05:08 24 4
gpt4 key购买 nike

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

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

TypeError: $mdSidenav is not a function

这是 HTML:

<!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>

和 JS:

'use strict';

angular.module('myApp', [
'ngMaterial'
])
.config([function () {
}])

.controller('mainCtrl', ['$scope', function ($scope, $mdSidenav) {
$scope.soKai = 'soKai';
$scope.currentTitle = 'Maths';
$scope.appName = 'KaiAcademics';
$scope.openSideNav = function(componentId) {
$mdSidenav(componentId).toggle();
}
}])
;

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

最佳答案

您忘记注入(inject) $mdSidenav

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

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

关于javascript - Angular Material $mdSidenav 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35456588/

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