Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular – 外部javascript库在'{module} / dist /’上返回404大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在Angular2中配置外部项目总是遇到一些麻烦.

我想在我的项目中包含ng2-sharebuttons. (它似乎没有全局.d.ts文件?)

然README.md只是说npm install ng2-sharebuttons –save,但我知道还有更多内容(systemjs.config& typings)

首先,我尝试配置systemjs.config

@H_96_13@map{ ...... 'ng2-sharebuttons' : 'node_modules/ng2-sharebuttons' }

这至少修复了localhost / ng2-sharebuttons上的404,但在localhost / node_modules / ng2-sharebuttons上创建了一个新的404.

所以,我添加一个文件,将systemjs.config更改为

@H_96_13@map{ ...... 'ng2-sharebuttons' : 'node_modules/ng2-sharebuttons/dist/index.js' }

但是现在这导致ng2-sharebuttons / dist的每个孩子都有404

我尝试使用和不使用–global标志安装ng2-sharebuttons –save –global和typings install @ types / ng2-sharebuttons –save –global.

所以在我最后的希望中,我添加一个,看看是否可行.添加

///< reference path =“../../ node_modules / ng2-sharebuttons / dist / index.d.ts”/>

但这并没有改变任何事情.

我忘记了什么?为什么这么难? (或者我只是努力吗?)

结构与ng2-sharebuttons文件

angular – 外部javascript库在'{module} / dist /’上返回404

最后,Chrome目前正在生成错误消息:

angular – 外部javascript库在'{module} / dist /’上返回404

整个systemjs.config.js

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(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: 'app',// 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.UR_56_11845@d.js',// other libraries
      'rxjs': 'npm:rxjs','angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js','angularfire2' : 'npm:angularfire2/bundles/angularfire2.umd.js','firebase' : 'npm:firebase','ng2-bs3-modal': 'npm:ng2-bs3-modal','ng2-sharebuttons' : 'npm:ng2-sharebuttons/dist/index.js','ng2-social-share' : 'npm:ng2-social-share/bundles/ng2-social-share.js'
    },// packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',defaultExtension: 'js'
      },rxjs: {
        defaultExtension: 'js'
      },firebase: {
        main: './firebase-browser.js',defaultExtension: 'js'
      }
    }
  });
})(this);

它抛出一个错误GET …. 404但也是一个XHR完成加载:GET ….在相同的组件/服务/文件,这似乎很奇怪.

解决方法

你需要这样做

@H_96_13@map:{ 'ng2-sharebuttons' : 'npm:ng2-sharebuttons/dist' },packages: { app: {main: './main.js',defaultExtension: 'js'},rxjs: {defaultExtension: 'js'},'ng2-sharebuttons': {main: 'index.js',defaultExtension: 'js'} }

大佬总结

以上是大佬教程为你收集整理的angular – 外部javascript库在'{module} / dist /’上返回404全部内容,希望文章能够帮你解决angular – 外部javascript库在'{module} / dist /’上返回404所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。