Skip to content

Commit

Permalink
Injector not set error repro
Browse files Browse the repository at this point in the history
  • Loading branch information
pobrienms committed Sep 14, 2017
1 parent 0d879a2 commit dba0dc6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 15 deletions.
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
},
"private": true,
"dependencies": {
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"@angular/common": "^4.2.0",
"@angular/compiler": "^4.2.0",
"@angular/core": "^4.2.0",
"@angular/forms": "^4.2.0",
"@angular/http": "^4.2.0",
"@angular/platform-browser": "^4.2.0",
"@angular/platform-browser-dynamic": "^4.2.0",
"@angular/router": "^4.2.0",
"@angular/upgrade": "^4.3.6",
"@ngrx/effects": "^4.0.5",
"@ngrx/store": "^4.0.3",
"angular": "^1.6.6",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"rxjs": "^5.4.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/compiler-cli": "^4.2.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
Expand All @@ -41,6 +45,6 @@
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
"typescript": "~2.5.2"
}
}
46 changes: 43 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,59 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { StoreModule, Store, Action } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';

import { UpgradeModule } from '@angular/upgrade/static';
import { MyEffects } from './my.effects';

import { AppComponent } from './app.component';

export function rootScopeFactory($injector) {
return $injector.get('$rootScope');
}


export interface State {
ids: string[];
}

export const initialState: State = {
ids: [],
};

export function reducer(state = initialState, action: Action): State {
switch (action.type) {
default:
return state;
}
}

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
HttpModule,
UpgradeModule,
StoreModule.forRoot(reducer),
EffectsModule.forRoot([MyEffects]),
],
providers: [
{
provide: '$rootScope', useFactory: rootScopeFactory, deps: ['$injector']
}
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {
constructor(private upgrade: UpgradeModule) {}

public ngDoBootstrap() {
this.upgrade.bootstrap(document.getElementById('appPlaceHolder'),
null,
{ strictDi: true });
}
}
25 changes: 25 additions & 0 deletions src/app/my.effects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/switchMap';
import { Inject, Injectable } from '@angular/core';
import { Action } from '@ngrx/store';
import { Effect, Actions, toPayload } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';

import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';


@Injectable()
export class MyEffects {

@Effect()
someEffect$: Observable<Action> = this.action$
.ofType('any')
.map(toPayload)
.switchMap((payload) => payload);

constructor(private action$: Actions, @Inject('$rootScope') private $rootScope) {
}
}
6 changes: 5 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
<!-- <app-root>Loading...</app-root> -->

<div id='appPlaceHolder' class="themeYellowDark">
<app-root></app-root>
</div>
</body>
</html>

0 comments on commit dba0dc6

Please sign in to comment.