安装Angular Material,“无法实例化模块ngMaterial”,即使我使用的是角度版本1.3.0

问题描述 投票:16回答:1

这是非常令人沮丧的,我使用一个mean.js自耕农生成的应用程序,似乎无法得到角度材料启动和运行。我读了另一个关于问题Angularjs with material design Failed to instantiate module ngMaterial的stackoverflow问题。所以我更新了我的bower.json文件并运行了bower updatebower install。它仍然无法正常工作。在凉亭更新期间,凉亭给了我这个消息Unable to find a suitable version for angular, please choose one:,但我总是选择Angular 1.3.0或更高版本。 下面是我的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'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

Angular config.js文件:

'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
    };
})();

在此先感谢您的帮助!

javascript angularjs angular-material
1个回答
35
投票

角质材料ngMaterial也依赖于ngAriangAnimate。你需要加载它们。

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

你可以从angular ariaangular animate下载它。根据角度版本使用正确的版本。

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

© www.soinside.com 2019 - 2024. All rights reserved.