【问题标题】:Module 'ngMaterial' is not available! You either misspelled the module name or forgot to load it模块“ngMaterial”不可用!您要么拼错了模块名称,要么忘记加载它
【发布时间】:2017-09-26 23:05:39
【问题描述】:

我正在使用 AngularJS v1.6.0。

我的代码:

var app= angular.module("appp",["ngMaterial"]);

错误:Module 'ngMaterial' is not available! You either misspelled the module name or forgot to load it.

这个 SO solution 说包括 ngAriangAnimate,我这样做了:

var app= angular.module("charter",["ng","ngAnimate","ngAria","ngMaterial"]);

现在我收到此错误:

Module 'ngAnimate' is not available! You either misspelled the module name or forgot to load it.

在我的 HTML 中,<head><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script>

我需要更多的依赖吗?

【问题讨论】:

  • 当您没有在 HTML 中包含脚本时,通常会出现此错误。如果您在 angular 本身之前放入脚本 angular 材料,有时会发生这种情况。
  • 在我的 HTML 中 <head><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script>
  • 在问题中粘贴你的 html ;)
  • 是的,您还需要包含角度材料依赖项!检查此代码笔:codepen.io/team/AngularMaterial/pen/RrbXyW

标签: angularjs


【解决方案1】:

您错过了将脚本包含到角材料中。 来自官方 Angular Material Codepen

<html lang="en" >
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Angular Material style sheet -->
  <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.css">
</head>
<body ng-app="BlankApp" ng-cloak>
  <!--
    Your HTML content here
  -->  

  <!-- Angular Material requires Angular.js Libraries -->
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js"></script>

  <!-- Angular Material Library -->
  <script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.js"></script>

  <!-- Your application bootstrap  -->
  <script type="text/javascript">    
    /**
     * You must include the dependency on 'ngMaterial' 
     */
    angular.module('BlankApp', ['ngMaterial']);
  </script>

</body>
</html>

<!--
Copyright 2016 Google Inc. All Rights Reserved. 
Use of this source code is governed by an MIT-style license that can be in foundin the LICENSE file at http://material.angularjs.org/license.
-->

【讨论】:

    猜你喜欢
    • 2016-07-21
    • 2017-06-29
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多