Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carlo-colombo/angular-routing
angular routing builder
https://github.com/carlo-colombo/angular-routing
Last synced: 8 days ago
JSON representation
angular routing builder
- Host: GitHub
- URL: https://github.com/carlo-colombo/angular-routing
- Owner: carlo-colombo
- License: mit
- Created: 2013-07-18T20:29:02.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-05T06:54:55.000Z (over 10 years ago)
- Last Synced: 2024-10-10T11:42:03.912Z (29 days ago)
- Language: JavaScript
- Size: 195 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
angular-routing
==================
Module to that aim to create rest routes for resource with minimal configuration. Inspired by server side mvc framework
###Add module to you app
`angular.module('app',['ngRouting'])`###Configure your resource
```javascript
app.config(function (routingProvider) {
routingProvider.withResolve({
//default resolve object for ruotes, can be overwritten by individual routes
user: function (authClient) {
return authClient.user
}
}).build([{
model:'book', //first level resource
nested:[{
model:'page' //second level resource
}]
}]) //return a angular $routeProvider to allow additional chaining
.when('/',{
redirectTo:'/books'
})
.when('/login',{
controller:'LoginCtrl as loginPage',
templateUrl:'views/login/index.html'
})
.otherwise({
redirectTo:'/books'
})
})
```
###Generated routes
```javascript
routingProvider.build([{
model:'book'
}])
```
##routes, controllers, views
| route | controller | view |
| ----------------------- |:-----------------|:---------------------|
| /books | BookListCtrl | views/book/list.html |
| /books/new | NewBookCtrl | views/book/new.html |
| /books/:bookId | BookCtrl | views/book/show.html |
| /books/:bookId/edit | EditBookCtrl | views/book/edit.html |###Nested routes
```javascript
routingProvider.build([{
model:'book',
nested:[{
model:'page'
}]
}])
```
####Nested routes start from parent level show route
```
/books/:bookId/pages
/books/:bookId/pages/new
/books/:bookId/pages/:pageId
/books/:bookId/pages/:pageId/edit
```####Nested routes vies are not nested eg: `views/page/show.html`
###Helpers method (rails inspired)
```javascript
//publish on $rootScope for convenience
app.run(function ($rootScope,routing) {
$rootScope.h = routing.helpers
})
```
Helper functions generate urls matching with configured `$locationProvider.html5Mode()` and `$locationProvider.hashPrefix()`
```
booksPath()
newBookPath(bookId)
bookPath(bookId)
editBookPath(bookId)bookPagesPath(bookId)
newBookPagePath(bookId)
bookPagePath(bookId,pageId)
editBookPagePath(bookId,pageId)
```###Additional model actions
```javascript
routingProvider.build([{
model:'book', //first level resource
actions:['lend']
}])
```
| route | controller | view |
| ----------------------- |:-----------------|:---------------------|
| /books/:bookId/lend | BookLendCtrl | views/book/lend.html |