使用 ng2-material 会出现错误“Uncaught ReferenceError: require is not defined"; [英] using ng2-material gives error "Uncaught ReferenceError: require is not defined"

查看:31
本文介绍了使用 ng2-material 会出现错误“Uncaught ReferenceError: require is not defined";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angular 2 创建一个应用程序.我想在我的应用程序中使用 angular 材料.但角度材料尚不可用于角度 2 我尝试在我的应用程序中使用 ng2-material 我使用 npm install 安装它并在应用程序组件中添加材料指令并将其映射到 index.php 中,如下所示但是当我尝试运行应用程序时它给出了错误.

I'm creating a app using angular 2. I want to use angular material in my app. but angular material not yet available for angular 2 I try to use ng2-material in my app I install it using npm install and add material directive in app component and map it in the index.php like below but when I try to run the application it gives errors.

index.php

<!doctype html>
<html>

<head>
 <base href="/">
<title>Angular 2 QuickStart</title>
<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<link rel="stylesheet" href="node_modules/ng2-material/dist/ng2-material.css">
<link rel="stylesheet" href="node_modules/ng2-material/dist/font.css">  
<!-- 2. Configure SystemJS -->
<script>
  System.config({
   packages: {        
        app: {
            format: 'register',
            defaultExtension: 'js'
        },
        'ng2-material': {
            format: 'register',
            defaultExtension: 'js'
        }
        },
        map: {
        'ng2-material': 'node_modules/ng2-material'
        }
    });
  System.import('app/boot')
        .then(null, console.error.bind(console));
</script>

 </head>

 <!-- 3. Display the application -->
 <body>
   <my-app>Loading...</my-app>
 </body>

</html>

错误

未捕获的 ReferenceError: require 未定义

Uncaught ReferenceError: require is not defined

谁能帮我解决这个问题.

can anyone help me with this.

推荐答案

试试下面的系统配置

<script>

    System.config({
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js'
                },
                'ng2-material': {
                    defaultExtension: 'js'
                }
            ,
            map: {
                'ng2-material': 'node_modules/ng2-material'
            }
        },
        paths: {
        'ng2-material/*': 'node_modules/ng2-material/*'
    }
    });
    System.import('app/boot')
        .then(null, console.error.bind(console));
</script>

这篇关于使用 ng2-material 会出现错误“Uncaught ReferenceError: require is not defined";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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