安装 Angular Material,“无法实例化模块 ngMaterial"即使我使用的是 Angular 版本 1.3.0 [英] Installing Angular Material, "Failed to instantiate module ngMaterial" even though I'm using angular version 1.3.0

查看:31
本文介绍了安装 Angular Material,“无法实例化模块 ngMaterial"即使我使用的是 Angular 版本 1.3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这非常令人沮丧,我使用的是 mean.js yeoman 生成的应用程序,但似乎无法启动和运行 angular-material.我阅读了另一个关于该问题的 stackoverflow 问题 Angularjs with material design Failed to实例化模块 ngMaterial.所以我更新了我的 bower.json 文件并运行了 bower updatebower install.它仍然不起作用.在 bower 更新期间,bower 给了我这个消息无法找到适合 angular 的版本,请选择一个:,但我总是选择 Angular 1.3.0 或更高版本.
这是我的 bower.json 的副本:

This is very frustrating, Im using a mean.js yeoman generated application and can't get to seem to get angular-material up and running. I read another stackoverflow question about the issue Angularjs with material design Failed to instantiate module ngMaterial. So I updated my bower.json file and ran a bower update and bower install. It still doesnt work. During the bower update, bower gave me this message Unable to find a suitable version for angular, please choose one:, but I always chose an Angular version 1.3.0 or greater.
Heres a copy of my bower.json:

{
  "name": "colign",
  "version": "0.0.1",
  "description": "Full-Stack JavaScript with MongoDB, Express, AngularJS, and Node.js",
  "dependencies": {
    "bootstrap": "~3",
    "angular": "~1.3",
    "angular-resource": "~1.3",
    "angular-mocks": "~1.3",
    "angular-bootstrap": "~0.11.2",
    "angular-ui-utils": "~0.1.1",
    "angular-ui-router": "~0.2.11",
    "angular-material": "~0.10.0"
  }
}

这是控制台错误消息:错误:[$injector:modulerr] 无法实例化模块 ngMaterial 由于:错误:[$injector:nomod] 模块ngMaterial"不可用!您拼错了模块名称或忘记加载它.如果注册模块,请确保将依赖项指定为第二个参数.

Heres the console error message: Error: [$injector:modulerr] Failed to instantiate module ngMaterial due to: Error: [$injector:nomod] Module 'ngMaterial' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Angular config.js 文件:

Angular config.js file:

'use strict';

// Init the application configuration module for AngularJS application
var ApplicationConfiguration = (function() {
    // Init module configuration options
    var applicationModuleName = 'colign';
    var applicationModuleVendorDependencies = ['ngResource', 'ui.router', 'ui.bootstrap', 'ui.utils', 'ngMaterial'];

    // Add a new vertical module
    var registerModule = function(moduleName, dependencies) {
        // Create angular module
        angular.module(moduleName, dependencies || []);

        // Add the module to the AngularJS configuration file
        angular.module(applicationModuleName).requires.push(moduleName);
    };

    return {
        applicationModuleName: applicationModuleName,
        applicationModuleVendorDependencies: applicationModuleVendorDependencies,
        registerModule: registerModule
    };
})();

在此先感谢您的帮助!

推荐答案

Angular 材质,ngMaterial,依赖于 ngAriangAnimate 作为好.您需要加载它们.

Angular material, ngMaterial, has dependency on ngAria and ngAnimate as well. You would need to load them.

angular.module('ngMaterial', ["ng","ngAnimate","ngAria", ...other material sub modules

您可以从 angular aria<下载它/a> 和 角度动画.根据您的角度版本使用正确的版本.

You could download it from angular aria and angular animate. Use the correct version of these based on your angular version.

此外,仅在项目中添加脚本是不够的,您还需要将它们加载到 html 中.还要在 ng-material 脚本之前加载它们.

Also just adding the scripts in the project is not enough you need to load them in your html as well. Also load them before ng-material script.

这篇关于安装 Angular Material,“无法实例化模块 ngMaterial"即使我使用的是 Angular 版本 1.3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆