zoukankan      html  css  js  c++  java
  • angular的uiRouter服务学习(5) --- $state.includes()方法

    $state.includes方法用于判断当前激活状态是否是指定的状态或者是指定状态的子状态.

    $state.includes(stateOrName,params,options)

    $state.includes方法接受三个参数,其中第二和第三个都不知道是干啥的...估计也不太用得到,就暂时不管了...

    stateOrName:字符串(必填). 是一个状态的名字.

    比如当前的激活状态是 "contacts.details.item" 

    如下调用:

    $state.includes("contacts");                              //返回true
    $state.includes("contacts.details");                      //返回true
    $state.includes("contacts.details.item");                 //返回true
    $state.includes("detail");                                //返回undefined
    $state.includes("item");                                  //返回undefined

    也可以使用glob语法:

    $state.$current.name = 'contacts.details.item.url';
     
    $state.includes("*.details.*.*"); // returns true
    $state.includes("*.details.**"); // returns true
    $state.includes("**.item.**"); // returns true
    $state.includes("*.details.item.url"); // returns true
    $state.includes("*.details.*.url"); // returns true
    $state.includes("*.details.*"); // returns undefined
    $state.includes("item.**"); // returns undefined

    可以用于激活某个tab,让当前项高亮显示:

    <li ng-class="{active:state.includes('dashboard.report')}"><a ui-sref="dashboard.report">Reports</a></li>

    需要注意的是,在表达式里直接用$state是不行的,需要在控制器中把$state赋值给$scope下的变量.这样在表达式里才能使用:

        $stateProvider.state('dashboard',{
            url:'/dashboard',
            templateUrl:'./tpls/dashboard.html',
            controller:function($scope,$state){
                $scope.state = $state;              
            }
        })
  • 相关阅读:
    github国内加速
    js 关闭MediaDevices.getUserMedia()
    windows server 安装 mysql + nondejs连接mysql
    sql常用语法大全
    当小程序的flex布局遇到button时,justify-content不起作用的原因及解决方案
    c# 使用Sharp7对PLC读写操作
    c#中引用c++动态库
    Python+Django
    python+pycharm+Django报错
    Dapper支持各类数据库(mysql,mssql,FireBird,Oracle)
  • 原文地址:https://www.cnblogs.com/liulangmao/p/4533922.html
Copyright © 2011-2022 走看看