jvandemo / generator-angular2-library

Yeoman generator to create an Angular library
MIT License
752 stars 122 forks source link

fix(playground): httpClient not usable #234

Closed davinkevin closed 6 years ago

davinkevin commented 7 years ago

Hello,

If I want to use inside my service the new httpClient from angular located in the package @angular/common/http, I get multiple errors, especially one linked to tslib

image

My service looks like this :

import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';

@Injectable()
export class SampleService {
    constructor(private http: HttpClient) {}
}

And my systemjs-config.js :

'use strict';
/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function () {
  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/common/http': 'npm:@angular/common/bundles/common-http.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',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'test-lib-angular': '../dist',
      'tslib': 'npm:tslib'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'test-lib-angular': {
        main: 'test-lib-angular.umd.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

I've added to this config the two following lines to enable the system to fetch those lib :

'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
'tslib': 'npm:tslib'

/cc @Neonox31

Thanks for your help

iamsourabh-in commented 7 years ago

Same problem with me .

Its due to the below reason.

The library is not able to import HttpModule and neither HttpClientModule

Just came accross this.

image

markpenaranda commented 6 years ago

To fix the problem add the ff line in

/playground/systemjs.config.js

// under angular bundles '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js', 'tslib': 'npm:tslib/tslib.js',

screen shot 2017-12-11 at 5 01 29 am
izifortune commented 6 years ago

Thank you @markpenaranda