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.

  • 相关阅读:
    14.使用nodejs将规定格式的txt转化为json数据
    13.resize妙用(书上看到的)
    12.写了一个怪怪的边框
    11.一起来抄一个小小的提示菜单
    UI02-textfiled.按钮 uibutton
    UI01-UIview UIlable的属性
    OC9-内存管理
    OC8-属性 KVC是键值编码
    OC7-‍ 类目,延展 协议代理。
    OC6-block-函数指针
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4085956.html
Copyright © 2011-2022 走看看