[Angular 2] Router basic and Router Params
2016-04-18 02:40
567 查看
When we define router in Angualr 2, we use @RouteConcfig()
When we want to display component, we use <router-outlet>
When we want to navigate to component, we use [routerLink]="['routerName']"
When we want to access router params, we use RouterParams
When we want to access Rotuer itself, we use Router
1. In index.html:
2. Include router file:
3. Inject the provider:
4. @RouterConfig:
5. Inject ROUTER_DIRECTIVES:
6. Define the link:
7. Define the router-outlet:
8. If deal with RouterParams:
----------------
When we want to display component, we use <router-outlet>
When we want to navigate to component, we use [routerLink]="['routerName']"
When we want to access router params, we use RouterParams
When we want to access Rotuer itself, we use Router
1. In index.html:
<base href="/">
2. Include router file:
import 'angular2/router';
3. Inject the provider:
bootstrap(App, [ ROUTER_PROVIDERS ]);
4. @RouterConfig:
@RouteConfig([ {path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true}, {path: '/about', name: 'About', component: AboutComponent} ])
5. Inject ROUTER_DIRECTIVES:
directives: [HomeComponent, AboutComponent, ROUTER_DIRECTIVES],
6. Define the link:
<a href="" [routerLink]="['Home']">Home</a> <a href="" [routerLink]="['Home', {username: 'Hero'}]">Owner</a> <a href="" [routerLink]="['About']">About</a>
7. Define the router-outlet:
<nav> <a href="" [routerLink]="['Home']">Home</a> <a href="" [routerLink]="['Home', {username: 'Zhentian Wan'}]">Owner</a> <a href="" [routerLink]="['About']">About</a> </nav> <router-outlet></router-outlet>
8. If deal with RouterParams:
constructor(private _routeParams: RouteParams){ this.username = _routeParams.get('username'); }
----------------
相关文章推荐
- AngularJS最理想开发工具WebStorm
- AngularJS入门教程之AngularJS表达式
- AngularJS入门教程之AngularJS指令
- AngularJS入门教程之AngularJS模型
- AngularJS最理想开发工具WebStorm
- AngularJS展示数据的ng-bind指令和{{}} 区别
- angularjs结合localstorage完成一个简单的备忘录
- AngularJS学习笔记—事件指令
- angular的学习
- Angularjs基础(二)
- AngularJS 学习笔记 -- 指令(Directive)
- AngularJS中使用的表单验证
- angularstrap typeahead 处理异步数据
- AngularJS 最常用的八种功能
- AngularJS ng-repeat下使用ng-model
- AngularJs中promise 和 $q 的一点解释
- AngularJS解决第一次加载闪烁问题
- AngularJS Scope 继承解析
- angularjs 与 springmvc 遇到的一些问题
- angular.element()的用法