title: Unable to use canDeActivate or canActivate in Angular
body: <p>I am trying to use the canDeActivate and canActivate and I am using it as below with Angular 4. I am getting a <code>no provider error</code> for the same. What is wrong with the implementation or what is the right way to implement this cleanly and simply.</p>
  
  <pre><code>import {ModuleWithProviders, } from '@angular/core';
  
      import {Routes, RouterModule, RouterStateSnapshot, ActivatedRouteSnapshot, CanDeactivate} from '@angular/router';
  
  
      import {HomeComponent} from '../home/home.component';
  
      var x: any = true;
  
      const appRoutes: Routes = [
          {path: '', component: HomeComponent, canDeactivate: [true]},
          {path: 'test', component: HomeComponent, canDeactivate: [x]},
  
      ];
  
      export const appRoutingProviders: any[] = [];
  
      export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
  </code></pre>
  
  <p>Update of the error:</p>
  
  <pre><code>ERROR Error: Uncaught (in promise): Error: No provider for true!
  Error: No provider for true!
      at injectionError (reflective_errors.ts:71)
      at noProviderError (reflective_errors.ts:105)
      at ReflectiveInjector_._throwOrNull (reflective_injector.ts:500)
      at ReflectiveInjector_._getByKeyDefault (reflective_injector.ts:543)
      at ReflectiveInjector_._getByKey (reflective_injector.ts:404)
      at ReflectiveInjector_.get (reflective_injector.ts:349)
      at AppModuleInjector.NgModuleInjector.get (ng_module_factory.ts:141)
      at PreActivation.getToken (router.ts:1232)
      at MergeMapSubscriber.eval [as project] (router.ts:1191)
      at MergeMapSubscriber._tryNext (mergeMap.ts:125)
      at injectionError (reflective_errors.ts:71)
      at noProviderError (reflective_errors.ts:105)
      at ReflectiveInjector_._throwOrNull (reflective_injector.ts:500)
      at ReflectiveInjector_._getByKeyDefault (reflective_injector.ts:543)
      at ReflectiveInjector_._getByKey (reflective_injector.ts:404)
      at ReflectiveInjector_.get (reflective_injector.ts:349)
      at AppModuleInjector.NgModuleInjector.get (ng_module_factory.ts:141)
      at PreActivation.getToken (router.ts:1232)
      at MergeMapSubscriber.eval [as project] (router.ts:1191)
      at MergeMapSubscriber._tryNext (mergeMap.ts:125)
      at resolvePromise (zone.js:769)
      at resolvePromise (zone.js:740)
      at zone.js:817
      at ZoneDelegate.invokeTask (zone.js:424)
      at Object.onInvokeTask (ng_zone.ts:253)
      at ZoneDelegate.invokeTask (zone.js:423)
      at Zone.runTask (zone.js:191)
      at drainMicroTaskQueue (zone.js:584)
      at HTMLAnchorElement.ZoneTask.invoke (zone.js:490)
  </code></pre>