使用 ng2

编程入门 行业动态 更新时间:2024-10-26 00:25:50
本文介绍了使用 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

本文发布于:2023-06-04 08:32:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/493298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!