【问题标题】:Failed to load resource angular2-cookie加载资源 angular2-cookie 失败
【发布时间】:2016-10-19 07:43:22
【问题描述】:

我正在尝试使用 Visual Studio 在 angular-2 的快速启动中添加“angular2-cookie”。

关注https://www.npmjs.com/package/angular2-cookie

到目前为止,我已经进行了以下更改。

npm install angular2-cookie --save

System.config
  map: 
   // other libraries
    'angular2-cookie': 'npm:angular2-cookie'

  packages:'angular2-cookie': {
  main: './core.js',
  defaultExtension: 'js'
  }

  app.component.ts

    import { CookieService } from 'angular2-cookie/services/cookies.service';

    providers: [CookieService]

   constructor(private _cookieService: CookieService) {
    _cookieService.put("test.com", "testCookie");
    console.log(_cookieService.get('test.com'));

应用程序构建良好,但最终出现加载资源失败:服务器响应状态为 404(未找到)

错误:(SystemJS) XHR 错误 (404 Not Found) loading http://localhost:56249/angular2-cookie/services/cookies.service(...)

我错过了什么?

完整代码

系统配置:

 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.umd.js',
  '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',

  // other libraries
  'rxjs':                      'npm:rxjs',
  'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
  'angular2-cookie': 'npm:angular2-cookie'
},
// 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'
  },
  'angular-in-memory-web-api': {
    main: './index.js',
    defaultExtension: 'js'
  },
  'angular2-cookie': {
  main: './core.js',
  defaultExtension: 'js'
  }
}  });

app.component.ts

import { Component } from '@angular/core';
import { CookieService } from 'angular2-cookie/services/cookies.service';


@Component({
selector: 'my-app',
template: '<h1>Quickstart for angular</h1><div> Hello there!</div>',
providers: [CookieService]

})
export class AppComponent {

constructor(private _cookieService: CookieService) {
    _cookieService.put("test.com", "testCookie");
    console.log(_cookieService.get('test.com'));

}

}

【问题讨论】:

    标签: angular angular2-cookie


    【解决方案1】:

    同样的代码今天也可以使用。似乎重建,删除浏览器缓存有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2018-01-15
      • 2013-02-26
      • 2019-05-28
      • 2016-06-24
      • 2016-07-01
      • 2011-06-21
      相关资源
      最近更新 更多