3

I've followed the starter app at: 'Learn in 5 mins' from https://angular.io/. I want to start trying to use the 'new' router, but when I do a:

import {...} from 'angular2/router';

I get a:

 error TS2307: Cannot find external module 'angular2/router'.

Can I add this dependency in a manner similar to how angular2 was installed. Namely, similar to:

tsd query angular2 --action install
ftravers
  • 3,809
  • 3
  • 37
  • 38

5 Answers5

1

tsd install will only add the type definition files used by TypeScript.

I don't believe the 5 minute demo is setup for using the router yet. If you need a quick fix, add a link to the router code <script src="https://code.angularjs.org/2.0.0-alpha.28/router.dev.js"></script> with a matching version number.

Perhaps a better alternative would be using one of the many angular 2 boilerplates out there. There isn't much sense in approaching the setup learning curve as it will be greatly simplified after Angular leaves alpha.

shmck
  • 5,129
  • 4
  • 17
  • 29
1

you get this error because angular2/router module is not defiend in your tsd.d.ts file. you can get out from this error by these methods.

1 command for install typings and add as your refference in the tsd.d.ts file.

tsd install angular2/router --save
  1. or you can add link to the router code

    <script src="https://code.angularjs.org/2.0.0-alpha.37/router.dev.js"></script>

i hope by following this you get your fix for your problem.

Pardeep jain
  • 90
  • 1
  • 8
0

You need angular router definition. I fix the problem using ng2.d.ts from angular2-webpack-starter

0

As of Angular 2.0 alpha 30 it's easier to use the router Here is an example of how to use it: http://www.syntaxsuccess.com/viewarticle/routing-in-angular-2.0

TGH
  • 38,769
  • 12
  • 102
  • 135
0

The router is contained in its own separate package

tsd install angular2/router --save

To import use:

import { 
    ROUTER_DIRECTIVES,
    ROUTER_PROVIDERS,
    RouteConfig,
} from 'angular2/router';

ROUTER_DIRECTIVES gets added to your @View.directives property. It includes the RouterLink and RouterOutlet classes.

RouteConfig is required to add a @RouteConfig decorator to your component.

ROUTER_PROVIDERS is required to bootstrap your router. It includes the RouteConfig (ie your defined routes) and sets PathLocationStrategy as your default LocationStrategy.

Ex.

bootstrap(App, [
    ROUTER_PROVIDERS,
]);
Evan Plaice
  • 13,944
  • 6
  • 76
  • 94