【问题标题】:using ng2-material gives error "Uncaught ReferenceError: require is not defined"使用 ng2-material 会出现错误“未捕获的 ReferenceError:未定义要求”
【发布时间】:2016-05-12 23:10:38
【问题描述】:

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

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>

错误

Uncaught ReferenceError: require is not defined

谁能帮帮我。

【问题讨论】:

    标签: angular


    【解决方案1】:

    尝试以下系统配置

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

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2020-07-13
      • 2018-01-25
      • 2019-03-05
      • 2022-06-15
      • 1970-01-01
      • 2016-11-10
      • 2015-11-14
      • 2020-05-16
      相关资源
      最近更新 更多