[Angular-Scaled web] 5. ui-router $stateParams for sharing information

When using ui-route, we want to pass the information with the url. 

 

Example:

angular.module('categories.bookmarks', [
    'categories.bookmarks.create',
    'categories.bookmarks.edit',
    'eggly.models.categories',
    'eggly.models.bookmarks'
])

    .config(function ($stateProvider) {
        $stateProvider
            .state('eggly.categories.bookmarks', {
                url: 'categories/:category',
                views: {
                    'bookmarks@': {
                        controller: 'BookmarksController',
                        templateUrl: 'app/categories/bookmarks/bookmarks.tmpl.html'
                    }
                }
            })

    })

    .controller('BookmarksController', function ($scope, $stateParams) {

        $scope.currentCategory = $stateParams.category;
        $scope.stateParams = $stateParams;
    })
;

 

Using :category to pass the params in url. And we can get the params in Controller by using $stateParams.

 

posted @ 2014-11-09 18:38  Zhentiw  阅读(372)  评论(0编辑  收藏  举报