Reputation: 4009
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
Upvotes: 3
Views: 2732
Reputation: 14140
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,
]);
Upvotes: 0
Reputation: 90
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
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.
Upvotes: 1
Reputation: 39278
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
Upvotes: 0
Reputation: 26
You need angular router definition. I fix the problem using ng2.d.ts from angular2-webpack-starter
Upvotes: 0
Reputation: 5629
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.
Upvotes: 1