I have problem using Angular2 Router, and I can't work it out.
This is my index.html
<html lang="">
<head>
<title>Angular2 Webpack Starter by @gdi2990 from @AngularClass</title>
...
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2.dev.js"></script>
<!-- base url -->
<base href="/">
<!--
Angular 2
ES6 browser shim
-->
<script src="/lib/es6-shim.js"></script>
</head>
<body>
<app>
Loading...
</app>
......
</body>
</html>
This is my app.ts:
/*
* Angular 2 decorators and services
*/
import {Directive, Component, View, ElementRef} from 'angular2/angular2';
import {RouteConfig, Router} from 'angular2/router';
import {Http, Headers} from 'angular2/http';
/*
* Angular Directives
*/
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/angular2';
import {ROUTER_DIRECTIVES} from 'angular2/router';
import {RouterLink} from 'angular2/router';
import {Home} from '../components/home/home';
import {Banner} from '../components/banner/banner';
import {PickVideo} from '../components/pickvideo/pickvideo'
/*
* App Component
* Top Level Component
*/
@Component({
selector: 'app',
directives: [ CORE_DIRECTIVES, FORM_DIRECTIVES, ROUTER_DIRECTIVES, RouterLink, Home, Banner ],
...
template: `
<div class="container">
<header>
<banner></banner>
</header>
<main>
<router-outlet></router-outlet>
</main>
</div>
`
})
@RouteConfig([
{ path: '/', redirectTo: 'home'},
{ path: '/home', as: 'Home', component: Home },
{ path: '/pick-video', as: 'PickVideo', component: PickVideo}
])
When page loads, it will redirect to Home, I import ROUTER_DIRECTIVES at home.ts
Inside my home.ts, I have a breadcrum.ts, which has html code like this:
<li class="active">
<a [routerLink]="['Home']">NAME YOUR APP</a>
</li>
<li>
<a [routerLink]="['PickVideo']">PICK YOUR VIDEOS</a>
</li>
I also import ROUTER_DIRECTIVES at breadcrumb.ts
but when I open the browser, the exception given like this:
Can't bind to 'routerlink' since it isn't a known native property in Breadcrumb > ol:nth-child(0) > li:nth-child(1) > a:nth-child(1)[[routerlink]=['Home']]
What I did:
I checked online, it says the directives: [ROUTER_DIRECTIVES] is missing, but I have add this line of code at both app.ts, home.ts, breadcrumb.ts, it's not working, any advise?
I am using the angular2-webpack-starter