angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

using third-party libs with ver5.0 #2737

Closed beshad closed 6 years ago

beshad commented 6 years ago
Item Version
generator-angular-fullstack x.x.x
Node x.x.x
npm x.x.x
Operating System OS X 10 / Windows 10 / Ubuntu 15.10 / etc
etc etc
Item Answer
Transpiler Babel / TypeScript
Markup HTML / Pug
CSS CSS / LESS / SCSS / Stylus
Router ngRoute / ui-router
Client Tests Jasmine / Mocha
DB MongoDB / SQL
Auth Y / N
etc etc

Hello,

I'm having problem using external libraries with version 5 (Angular) of this generator. i have used the AngularJS version of this many times and used the webpack vendor array to import libraries after installation via npm. have been trying to do the same and but they never worked. here is what i do:

in my webpack.make.js: vendor: [ ... 'ng2-toastr' ]

then in app.module.ts

import { ToastModule } from 'ng2-toastr/ng2-toastr'; ... imports: [ToastModule.forRoot()] ... and then use is as each library recommends in my components. (using ng-toast here as an example but i tried others too). same libabries work in a test project generated via angular-cli but here i get various error messages so i know they are not injected properly by me. is there anything that i am missing? the same process worked everytime in AnguarJS version of this generator. cheers

Awk34 commented 6 years ago

It would help if you shared the error messages

beshad commented 6 years ago

Hi Andrew thanks for the quick reply. i have tried multiple libs to see if its the individual library which i set up incorrectly or my import method to this generator. i get various errors regardless of what lib i use. for example here is the setup and error for ng2-toastr:

in main.module.ts:

import { Component, OnInit, ViewContainerRef } from '@angular/core';
import {ToastModule} from 'ng2-toastr/ng2-toastr'; and imports:[ToastModule.forRoot()]

then in main.component.ts:

import { ToastsManager } from 'ng2-toastr/ng2-toastr';

and

...
    constructor(public toastr: ToastsManager, vcr: ViewContainerRef) {
        this.toastr.setRootViewContainerRef(vcr);
    }

    ngOnInit() {
        this.toastr.success('You are awesome!', 'Success!');
    }

and there is the console error message:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'setRootViewContainerRef' of undefined
TypeError: Cannot read property 'setRootViewContainerRef' of undefined
    at new MainComponent (main.component.ts:21)
    at createClass (core.js:12481)
    at createDirectiveInstance (core.js:12326)
    at createViewNodes (core.js:13784)
    at createRootView (core.js:13673)
    at callWithDebugContext (core.js:15098)

thank you for your help

Awk34 commented 6 years ago

Well, a few minutes of searching tells me you're using a deprecated module..

use this: https://github.com/scttcper/ngx-toastr

Awk34 commented 6 years ago

Closing as this isn't an issue with the generator