title: Dispatch ngrx store action in route resolver
body: <p>I'm currently have a container (stateful) component which dispatches a <code>select</code> and a <code>get</code> action based on a route param (id) in the <code>ngOnInit</code> method. The point of these actions to have the data and the selected id in my store. </p>
  
  <p>I'm curious would it be correct to dispatch these actions in a resolver?</p>
  
  <p>Thanks for the replies.</p>
  
  <p>My component:</p>
  
  <pre><code>@Component({
    selector: 'app-container',
    templateUrl: './container.component.html',
    styleUrls: ['./container.component.css']
  })
  export class ContainerComponent implements OnInit, OnDestroy {
  
    private componetDestroyed$ = new Subject();
  
    constructor(private store: Store&lt;fromRoot.State&gt;, private route: ActivatedRoute) { }
  
    ngOnInit() {
      this.route.params
        .filter(params =&gt; params['id'])
        .map(params =&gt; params['id'])
        .takeUntil(this.componetDestroyed$)
        .subscribe(id =&gt; {
          this.store.dispatch(new GetAction(id));
          this.store.dispatch(new SelectAction(id));
        });
    }
  
    ngOnDestroy() {
      this.componetDestroyed$.next();
      this.componetDestroyed$.unsubscribe();
    }   
  }
  </code></pre>
  
  <p>My routes:</p>
  
  <pre><code>[{
    path: ':id',
    component: ContainerComponent
  }]
  </code></pre>
  
  <p>The resolver would be:</p>
  
  <pre><code>@Injectable()
  class MyResolver implements Resolve&lt;any&gt; {
  
  constructor(private store: Store&lt;fromRoot.State&gt;) {}
  
  resolve(route: ActivatedRouteSnapshot, state: RouteStateSnapshot) {
    let id = route.params['id'];
    this.store.dispatch(new SelectAction(id));
    this.store.dispatch(new GetAction(id));
    return null;
  }
  </code></pre>
  
  <p>And the modified routes:</p>
  
  <pre><code>[{
    path: ':id',
    component: ContainerComponent,
    resolve: {
      store: MyResolver
    }
  }]
  </code></pre>
  
  <p>And that's why I'm not sure this is correct, becuase the store will always be <code>null</code>.</p>