zoukankan      html  css  js  c++  java
  • [Angular-Scaled Web] 6. Navigating between states with ui-router

    There are two ways to naviagting between state:
      1. Using $state service, $state.go()

      2. Using ui-serf diretive

    $state.go

    Inject $state service.

       .controller('MainController', function ($scope , $state) {
      
           ...
    
            function setCurrentCategory(category) {
    
                $scope.currentCategory = category;
                $state.go('eggly.categories.bookmarks', {category: category.name});
    
                cancelCreating();
                cancelEditing();
            }
    
            ....

    $state.go('eggly.categories.bookmarks', {category: category.name}), 

    in which eggly.categories.bookmarks is state name in bookmarks.js and category: is the state param.

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

    ui-sref

    <a ng-click="setCurrentCategory(null)"><img class="logo" src="assets/img/eggly-logo.png"></a>
    <ul class="nav nav-sidebar">
        <li ng-repeat="category in categories" ng-class="{'active':isCurrentCategory(category)}">
            <a ui-sref="eggly.categories.bookmarks({category: category.name})" ng-click="setCurrentCategory(category)">
                {{category.name}}
            </a>
        </li>
    </ul>

    ui-sref="eggly.categories.bookmarks({category: category.name})", using state name: eggly.categories.bookmarks , as here function name.

  • 相关阅读:
    颜色透明度16进制对照表
    爬取代理IP
    Python中匹配IP的正则表达式
    IP地址正则表达式的写法
    每日一练 11.23
    每日一练 11.22
    每日一练
    pycharm使用教程
    周总结博客16
    周总结博客15
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4085956.html
Copyright © 2011-2022 走看看