maxisam / ngx-window-token

angular 2 window inject token
MIT License
20 stars 4 forks source link

Error: No provider for InjectionToken WindowToken #1

Closed GuyHarwood closed 7 years ago

GuyHarwood commented 7 years ago

Using angular 4 with webpack.

I add top level import...

import {WINDOW, WindowTokenModule} from 'ngx-window-token';

and also declare in module setup...

imports: [ BrowserModule, WindowTokenModule ]

However, when i create a service that uses it....

import {WINDOW, WindowTokenModule} from 'ngx-window-token';

@Injectable()
export class StorageService {

  private wdw : any

  constructor(@Inject(WINDOW) _window : any){
    this.wdw = _window
  }

  setItem(key : string, value : any) {
    wdw.localStorage.setItem(key, value)
  }

i get the following error...

Error: No provider for InjectionToken WindowToken!
    at injectionError (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:1169:22)
    at noProviderError (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:1207:1)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._throwOrNull (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:2649:1)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._getByKeyDefault (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:2688:1)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._getByKey (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:2620:1)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_.get (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:2489:1)
    at resolveNgModuleDep (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:9473:1)
    at _createClass (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:9512:1)
    at _createProviderInstance$1 (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:9484:1)
    at resolveNgModuleDep (http://localhost:9876/_karma_webpack_/webpack:/Users/guy/dev/mtc/pupil-spa/~/@angular/core/@angular/core.es5.js:9469:1)

What am i missing here?

Your readme states...

For webpack / Angular CLI, it works as any other libraries. Please check demo folder for more help.

However, there is no demo folder.

maxisam commented 7 years ago

do you check the plunker? https://plnkr.co/edit/uy2UfN0sD5I2qoNotGu7?p=preview

It should work. I will add demo soon

GuyHarwood commented 7 years ago

@maxisam The problem turned out to be a missing entry in provider declaration in a test.

it does actually work, but a demo would help anyone else new to this.

maxisam commented 7 years ago

Cool. I will add one soon.