在 angularJS2 项目中哪里放置/找到 systemjs.config.js 文件?

2024-03-16

我是 Angular 2 的新手,并尝试在我的项目中使用 ng2-datetime-picker。现在,在安装 ng2-datetime-picker 包后,当我运行该项目时,得到了404 错误指出未找到 ng2-datetime-picker,在浏览了一些博客之后,我发现我必须在 systemjs.config.js 文件中添加配置,但是当我浏览我的项目时,我在项目中看不到任何 systemjs.config.js 文件。所以我的问题是

  1. systemjs.config.js 文件存在于哪里?
  2. 下面的代码是 systemjs.config.js 文件吗

    System.import('app').catch(function (err) { console.error(err); });

  3. 如果是,那么如何将地图和包添加到该文件中

    地图[‘ng2-datetime-picker’] =‘node_modules/ng2-datetime-picker/dist’; 包['ng2-datetime-picker'] = { main: 'ng2-datetime-picker.umd.js', defaultExtension: 'js' }update 1

这是我的 systemjs.config.js 文件

(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app : 'ScriptsApp', // 'dist',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            // other libraries
            'rxjs': 'npm:rxjs',
            'ng2-datetime-picker': 'npm:ng2-datetime-picker'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: { main: './boot.js', defaultExtension: 'js' },
            rxjs: { defaultExtension: 'js' },
            'ng2-datetime-picker': { main: 'ng2-datetime-picker.umd.js', defaultExtension: 'js' }
        }
    });
})(this);

index.js 文件中添加的引用是

 <!-- Polyfills for older browsers -->
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://unpkg.com/[email protected] /cdn-cgi/l/email-protection?main=browser"></script>
    <script src="https://unpkg.com/[email protected] /cdn-cgi/l/email-protection/dist/system.src.js"></script>
    <script src="https://cdn.rawgit.com/angular/angular.io/b3c65a9/public/docs/_examples/_boilerplate/systemjs.config.web.js"></script>
    <script src="systemjs.config.js"></script>
    <script>
        System.import('app').catch(function (err) { console.error(err); });
    </script>

this is the error i am getting after adding the systemjs.config.js file and the refrence in the index.html file enter image description here


您需要创建一个“systemjs.config.js”文件并从index.html加载它,就像常规脚本一样:

 <script src="systemjs.config.js"></script>

确保在配置脚本之前还包含 System.JS:

<script src="node_modules/systemjs/dist/system.src.js"></script>

以下脚本加载第一个模块:

System.import('app').catch(function (err) { console.error(err); });

默认情况下(根据您的 systemjs.config.js),SystemJS 将查找 app.js 或 app/main.js。

在 systemjs.config.js 文件中,您希望将节点包映射到存在 index.js 或 package.json 的路径,该路径指示模块所在的位置。该模块应该与您打算使用的模块加载器兼容:AMD、UMD、CommonJS、SystemJS、es6 等

以下内容应该在您的 systemjs.config.js 文件中起作用:

'paths': {
    'npm:':'node_modules/'
},

'map': {
     'ng2-datetime-picker': 'npm:ng2-datetime-picker'
      ...
},
'packages':  {
     'ng2-datetime-picker': 'dist/ng2-datetime-picker.umd.js'
 }

或者,您可以直接映射 UMD 文件:

'paths': {
    'npm:':'node_modules/'
},

'map': {
     'ng2-datetime-picker': 'npm:ng2-datetime-picker/dist/ng2-datetime-picker.umd.js'
      ...
}

以下内容仅适用于 CommonJS/AMD/SystemJS,因为 index.js 使用“require”语法:

'paths': {
    'npm:':'node_modules/'
 },

'map': {
     'ng2-datetime-picker': 'npm:ng2-datetime-picker'
      ...
},
'packages':  {
     'ng2-datetime-picker': 'dist/index.js'
 }

EDIT

这应该有效:

    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
        app: { main: 'boot.js', defaultExtension: 'js' },
        rxjs: { defaultExtension: 'js' },
        'ng2-datetime-picker': { main: 'dist/ng2-datetime-picker.umd.js', defaultExtension: 'js' }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 angularJS2 项目中哪里放置/找到 systemjs.config.js 文件? 的相关文章

随机推荐

  • Unity3D 中 Update() 循环方法内的执行顺序

    我正在尝试找到合适的词语来描述我遇到的问题 希望这能解释问题 我有两个Update 两个不同类中的方法 并且一个类中的某些功能依赖于另一个类中的数据 代码 A 依赖于代码 B 的数据 使用调试日志 我发现代码B的Update 在代码 A 之
  • 如何从 HttpPost Create 操作方法中了解选定的复选框?

    我之间有多对多关系Student and Course 链接实体集是Enrollment 为了简单起见 它们都定义如下 Models public class Course public int Id get set public stri
  • 共享指针递归删除递归数据结构导致堆栈溢出

    我有许多长链接列表 它们最多有 20 000 个项目 它们有不同的起点 但最终可以从某个节点开始指向同一个节点 我决定让这样的链表一起成长并共享它们之间的记忆 这就是为什么我决定使用共享指针实现链表 include
  • Google 或其他搜索引擎执行 JavaScript 吗?

    我只是想知道 Google 或其他搜索引擎是否在您的网页上执行 JavaScript 例如 如果您使用 JavaScript 设置标题标签 Google 搜索引擎会看到它吗 出于 SEO 目的进行的一些实验表明 至少大公司 例如 Googl
  • 将 IDENTITY 转换为数据类型 int 时出现算术溢出错误 [已关闭]

    Closed 这个问题需要调试细节 help minimal reproducible example 目前不接受答案 通过 vb 代码运行时 将 IDENTITY 转换为数据类型 int 时发生算术溢出错误 但是当我执行存储过程时 数据会
  • AngularJS - 获取字段的标签文本

    Question 我想知道 AngularJS 获取字段标签的 最佳实践 方法是什么 使用 jQuery 您只需使用 label for 查询进行查询 然后提取文本 虽然用 AngularJS 可以做到这一点 但总感觉有些不对劲 假设您的
  • 使用 Python 将带有内嵌图像的电子邮件发送到 Gmail

    我的目标是使用 Python 向具有内嵌图像的 Gmail 用户发送电子邮件 无法在线托管此图像 然后通过href 由于图像的敏感性 来自我的工作的数据 我尝试过编码base64版本变成HTML然后发送的是HTML 但众所周知这是行不通的
  • 错误:GooglePlayServicesUtil:发生内部错误。请参阅日志以获取详细信息。我该如何解决?

    我花了无数的时间试图弄清楚这个 google Drive android api 并且我一直在试图弄清楚如何使用它 这让我自己感到非常沮丧 我正在使用入门链接 https developers google com drive androi
  • 无法使用 selenium 和 read_html 从宏观趋势检索数据来创建数据框?

    我想将宏观趋势数据导入 pandas 数据框架 从网站的页面源来看 数据似乎位于 jqxgrid 中 我尝试使用 pandas beautiful soup 和 read html 函数 但没有找到表 我目前正在尝试使用硒来提取数据 我希望
  • 如何解析/编码二进制消息格式?

    我需要用 Java 解析和编码为旧的二进制消息格式 我开始使用 DataOutputStream 来读取 写入基元类型 但我遇到的问题是消息格式与字节偏移量不能很好地对齐并且包含位标志 例如我必须处理这样的消息 uint32 b b uin
  • 如果 setUpClass 抛出异常,如何使 python 单元测试失败

    我在使用 python setUpClass 时遇到了一些问题 例如考虑以下情况 class MyTest unittest case TestCase classmethod def setUpClass cls print Test s
  • 定义一个不平凡的 Scala 案例类是否合适?

    我今天正在定义一个 Scala 类 我想 我需要一个equals方法和一个hashCode方法 和一个copy方法也会很方便 我将把它变成一个案例类 我的类已经有一堆其他代码 而且绝不是微不足道的 很好 一切都有效 但是当教科书处理案例类时
  • 获取Makefile中的源代码结构

    我正在开发一个 C 项目 我决定将源代码及其对象放在不同的目录中 根目录有类似这样的内容 SmartC tree L 1 built doc Makefile README md src tests trash 因此 在 src 和buil
  • Type.GetFields() - 只返回“public const”字段

    我想调用 Type GetFields 并且只返回声明为 public const 的字段 到目前为止我有这个 type GetFields BindingFlags Static BindingFlags Public 但这还包括 公共静
  • 访问不存在的缩略图

    我制作了一个应用程序 可以向您显示计算机中的文件列表 每当您单击列表中的任何项目时 它旁边的小图片框都会显示相应文件的缩略图 我在 Windows 7 上使用 C 为了获取缩略图 我重复使用了另一个问题中发布的方法 首先 我参考了 Wind
  • Swagger 参数和复杂类型

    在下面的 Swagger 定义中 我需要参数labelValue属于类型LabelValueObject 以便对其进行验证并正确反序列化 但是 我无法弄清楚语法 那怎么办呢 swagger 2 0 paths competition pos
  • Python 中的树实现

    如何在Python中实现树 我是Python初学者 给我一个大概的想法 Build a Node类 具有一些内容对象和子对象列表 它们又是Node
  • 使用 ACL 的 Redis Docker 镜像

    我正在尝试测试新的 Redis 6 ACL 配置 我想使用尽可能简单的配置来运行测试以熟悉配置 我的 Redis 将作为 Docker 容器运行 请考虑一下我是一个 Redis 新手 My Dockerfile FROM redis 6 2
  • “旧版”和“稳定版”有什么区别?

    我正在使用 JQuery Mobile 有两个可用版本 稳定版本和旧版本 我对后一种不太熟悉 什么是旧版本 或者说和稳定版有什么区别 生产现场推荐使用哪一种 非常感谢 遗留版本是旧的稳定版本 仍然可用 并且可能受支持 因为有人可能需要它 例
  • 在 angularJS2 项目中哪里放置/找到 systemjs.config.js 文件?

    我是 Angular 2 的新手 并尝试在我的项目中使用 ng2 datetime picker 现在 在安装 ng2 datetime picker 包后 当我运行该项目时 得到了404 错误指出未找到 ng2 datetime pick