| ui-router | ngRoute | |
|---|---|---|
| Common Factors | ||
| Module name (dependent module) | ui.router (eg) angular.module('app', ['ui.router']); |
ngRoute (eg) angular.module('app', ['ngRoute']); |
| Router provider | $stateProvider $urlRouterProvider |
$routeProvider |
| Simple Syntax |
$stateProvider.state('customersState', {
url: '/customers',
template: 'My Customers'
})
|
$routeProvider.when('/customers', {
template: 'My Customers'
});
|
| Template view directive | ui-view | ng-view |
| Template named view directive | ui-view="customers" | --- |
| Link directive | ui-sref="" (eg) <a ui-sref="customersState"> Customers </a> |
href="" (eg) <a href="#/customers"> Customers </a> |
| Params | ||
| Getting Params (as a service) | $state (eg) $state.params.id $staetParams (eg) $stateParams.id |
$route (eg) $route.current.params.id $routeParams (eg) $routeParams.id |
| Events | ||
| Router start event | $stateChangeStart | $routeChangeStart |
| Router success event | $stateChangeSuccess | $routeChangeSuccess |
| Router error event | $stateChangeError | $routeChangeError |
| Router update event | --- | $routeUpdate |
| Router not found event | $stateNotFound | --- |
| Default View | ||
| Default View | $urlRouterProvider.otherwise('/customers'); | $routeProvider.otherwise({redirectTo: '/customers'}); |
| Methods | ||
| One view to another view | $state.go('customersState'); | $location.path( "/customers" ); |
| One view to another view with params | $state.go('customersState', {id:'123'}); | $location.path( "/customer/123" ); |
AngularJS Coding Tips
Monday, August 3, 2015
Ui Route vs ngRoute
Wednesday, December 3, 2014
Why Angular ?
Why Angular ?
1. Organize javascript code.
2. Responsive websites
3. Plays really good with jQuery
4. Good for maintaince, since it has powerful testing API.
Subscribe to:
Comments (Atom)