AngularJS中ui-router全攻略

Git SSH密钥免密配置全攻略:告别重复输入passphrase SSH密钥认证是远程服务器安全访问和代码版本控制的核心机制,它基于非对称加密原理,通过公钥和私钥配对实现身份验证。在实际开发中,为私钥设置passphrase能显著提升安全性,但每次Git操作都需手动输入,会严重打断工作流。其技术价值在于通过ssh-agent密钥代理服务,将解密后的私钥缓存在内存中,实现单次认证、多次使用。这一机制广泛应用于持续集成、自动化部署及日常开发场景。本文聚焦于解决Git操作中反复要求输入SSH密钥passphrase的痛点,通过详解ssh-agent在Windows、macOS和 阅读详情

From:http://www.cnblogs.com/darrenji/p/5167999.html


首先是angular-ui-router的基本用法。

■ 如何引用依赖angular-ui-router

 

angular.module('app',["ui.router"])
    .config(function($stateProvider){
        $stateProvider.state(stateName, stateCofig);
    })

 

■ $stateProvider.state(stateName, stateConfig)

stateName是string类型
stateConfig是object类型

//statConfig可以为空对象
$stateProvider.state("home",{});

//state可以有子父级
$stateProvider.state("home",{});
$stateProvider.state("home.child",{})

//state可以是链式的
$stateProvider.state("home",{}).state("about",{}).state("photos",{});

stateConfig包含的字段:template, templateUrl, templateProvider, controller, controllerProvider, resolve, url, params, views, abstract, onEnter, onExit, reloadOnSearch, data

■ $urlRouteProvider

$urlRouteProvider.when(whenPath, toPath)
$urlRouterProvider.otherwise(path)
$urlRouteProvider.rule(handler)

■ $state.go

$state.go(to, [,toParams],[,options])
形参to是string类型,必须,使用"^"或"."表示相对路径;
形参toParams可空,类型是对象;
形参options可空,类型是对象,字段包括:location为bool类型默认true,inherit为bool类型默认true, relative为对象默认$state.$current,notify为bool类型默认为true, reload为bool类型默认为false

$state.go('photos.detail')
$state.go('^')到上一级,比如从photo.detail到photo
$state.go('^.list')到相邻state,比如从photo.detail到photo.list
$state.go('^.detail.comment')到孙子级state,比如从photo.detail到photo.detial.comment

■ ui-sref

ui-sref='stateName'
ui-sref='stateName({param:value, param:value})'

■ ui-view

==没有名称的ui-view

 

<div ui-view></div>

$stateProvider.state("home",{
    template: "<h1>hi</h1>"
})

 

或者这样配置:

 

复制代码
$stateProvider.state("home"{
    views: {
        "": {
            template: "<h1>hi</h1>"
        }
    }
})
复制代码

 

==有名称的ui-view

 

复制代码
<div ui-view="main"></div>

$stateProvider.state("home",{
    views: {
        "main" : {
            template: "<h1>hi</h1>"
        }
    }
})
复制代码

 

==多个ui-view

 

复制代码
<div ui-view></div>
<div ui-view="data"></div>

$stateProvider.state("home",{
    views: {
        "":{template: "<h1>hi</h1>"},
        "data": {template: "<div>data</div>"}
    }
})
复制代码

 


■ 项目文件结构

node_modules/
partials/
.....about.html
.....home.html
.....photos.html
app.js
index.html

■ 创建state和view

app.js

复制代码
var photoGallery = angular.module('photoGallery',["ui.router"]);

photoGallery.config(function($stateProvider, $urlRouterProvider){
    $urlRouterProvider.otherwise('/home');

    $stateProvider
        .state('home',{
            url: '/home',
            templateUrl: 'partials/home.html'
        })
        .state('photos',{
            url: '/photos',
            templateUrl: 'partials/photos.html'
        })
        .state('about',{
            url: '/about',
            templateUrl: 'partials/about.html'
        })
})
复制代码

 

index.html

复制代码
<!DOCTYPE html>
<html lang="en" ng-app="photoGallery">
<head>
  <meta charset="UTF-8">
  <title></title>
  <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css"/>
</head>
<body>

  <h1>Welcome</h1>
  <div ui-view></div>

<script src="node_modules/jquery/dist/jquery.js"></script>

<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
<script src="node_modules/angular-animate/angular-animate.js"></script>

<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script src="node_modules/angular-bootstrap/ui-bootstrap-tpls.js"></script>

<script src="app.js"></script>
</body>
</html>
复制代码

 

■ state之间的跳转

 

index.html

复制代码
<nav class="navbar navbar-inverse">
<div class="container-fluid">
  <div class="navbar-header">
    <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a ui-sref="home" class="navbar-brand">Home</a>
  </div>
  <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    <ul class="nav navbar-nav">
      <li>
        <a ui-sref="photos">Photos</a>
      </li>
      <li>
        <a ui-sref="about">About</a>
      </li>
    </ul>
  </div>
</div>
</nav>

<div ui-view></div>
复制代码

 

以上通过ui-sref属性完成state之间的跳转。

■ 多个view以及state嵌套

有时候,一个页面上可能有多个ui-view,比如:

<div ui-view="header"></div>
<div ui-view="body"></div>

假设,以上页面属于一个名称为parent的state中。

我们知道在ui-router中,一个state大致是这样设置的:

.state('content.photos',{
    url: 'photos',
    views:{
        "body@content":{templateUrl: 'partials/photos.html'}
    }
})

 

所有state下views下的所有键值对(类似 "body@content":{templateUrl: 'partials/photos.html'})都被放到一个键值集合中。而ui-view的工作原理就是根据自己的属性值,到这个键值集合中去找匹配的键,找到就把对应的页面显示出来。


点击header对应的页面链接,可能会跳转到另外的子页面出现在<div ui-view="body"></div>这个位置。这时候页面出现了子父关系,而每个页面都属于某个state,这样state间就出现了子父关系。这些跳转的子页面,在路由设置中,可能被称为parent.son1, parent.son2...这就是state的嵌套。

在现有的文件结构上增加content.html, header.html,文件结构变为:


node_modules/
partials/
.....about.html
.....home.html
.....photos.html
.....content.html
.....header.html
app.js
index.html

content.html 包含了多各ui-view, 一个ui-view和页头相关,保持不变;令一个ui-view和会根据页头上的点击呈现不同的内容


<div ui-view="header"></div>
<div ui-view="body"></div>


header.html 把原先indext.html中nav部分放到这里来

复制代码
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a ui-sref="content.home" class="navbar-brand">Home</a>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li>
          <a ui-sref="content.photos">Photos</a>
        </li>
        <li>
          <a ui-sref="content.about">About</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
复制代码

 

index.html 这时变成了这样

<div ui-view></div>

app.js 路由现在这样设置

 

复制代码
var photoGallery = angular.module('photoGallery',["ui.router"]);

photoGallery.config(function($stateProvider, $urlRouterProvider){
    $urlRouterProvider.otherwise('home');

    $stateProvider
        .state('content',{
            url: '/',
            views:{
                "":{templateUrl: 'partials/content.html'},
                "header@content":{templateUrl: 'partials/header.html'},
            }
        })
        .state('content.home',{
            url: 'home',
            views:{
                "body@content":{templateUrl: 'partials/home.html'}
            }
        })
        .state('content.photos',{
            url: 'photos',
            views:{
                "body@content":{templateUrl: 'partials/photos.html'}
            }
        })
        .state('content.about',{
            url:'about',
            views:{
                "body@content":{templateUrl: 'partials/about.html'}
            }
        })
})
复制代码

 

这时候,页面是这样呈现出来的:

→ 来到home这个路由

 

.state('content.home',{
    url: 'home',
    views:{
        "body@content":{templateUrl: 'partials/home.html'}
    }
})

 

以上,告诉我们partials/home.html将会被加载到与"body@content"匹配的ui-view中。暂时对应的ui-view还没有出现,于是等待。

→ 路由看到index.html上的<div ui-view></div>

 

复制代码
.state('content',{
    url: '/',
    views:{
        "":{templateUrl: 'partials/content.html'},
        "header@content":{templateUrl: 'partials/header.html'},
    }
})
复制代码

 

于是,就找到了content这个state下views下的 "":{templateUrl: 'partials/content.html'}这个键值对,把partials/content.html显示出来。

→ 分别加载partials/content.html页面上的各个部分

看到<div ui-view="header"></div>,就加载如下:

"header@content":{templateUrl: 'partials/header.html'},


看到<div ui-view="body"></div>,先加载 "body@content":{templateUrl: 'partials/home.html'}


→ 点击header上的链接

点击<a ui-sref="content.photos">Photos</a>,来到:

.state('content.photos',{
    url: 'photos',
    views:{
        "body@content":{templateUrl: 'partials/photos.html'}
    }
})

 

把partials/photos.html显示到<div ui-view="body"></div>中去。


点击<div ui-view="body"></div>,来到:

.state('content.about',{
    url:'about',
    views:{
        "body@content":{templateUrl: 'partials/about.html'}
    }
})

 

把partials/about.html显示到<div ui-view="body"></div>中去。


■ state多级嵌套

以上,在路由设置中,state名称有content, content.photos有了这样的一层嵌套。接下来,要实现state的多级嵌套。

在photos.html页面准备加载一个子页面,叫做photos-list.html;
与photo-list.html页面相邻的还有一个页面,叫做photo-detail.html;
在photo-detail.html页面上加载一个子页面,叫做photos-detail-comment.html;

这样,页面有了嵌套关系,state也相应的会有嵌套关系。

现在,文件结构变成:

node_modules/
partials/
.....about.html
.....home.html
.....photos.html
.....content.html
.....header.html
.....photos-list.html
.....photo-detail.html
.....photos-detail-comment.html
app.js
index.html

photos.html 加一个容纳子页面的ui-view

photos
<div ui-view></div>

如何到达这个子页面呢?修改header中的相关部分如下:

 

复制代码
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a ui-sref="content.home" class="navbar-brand">Home</a>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li>
          <a ui-sref="content.photos.list">Photos</a>
        </li>
        <li>
          <a ui-sref="content.about">About</a>
        </li>
      </ul>
    </div>
  </div>
复制代码

 

以上,通过<a ui-sref="content.photos.list">Photos</a>来到photos.html的子页面photos-list.html.

photos-list.html 通过2种途径到相邻页photo-detail.html

<h1>photos-list</h1>
<ul>
  <li><a ui-sref="^.detail">我通过相对路径到相邻的state</a></li>
  <li><a ui-sref="content.photos.detail">我通过绝对路径到相邻的state</a></li>
</ul>

 

photo-detail.html 又提供了来到其子页面photos-detail-comment.html的ui-view

<h1>photo-details</h1>
<a class="btn btn-default" ui-sref=".comment">通过相对路径去子state</a>
<div ui-view></div>

 

photos-detail-comment.html 则很简单:
<h1>photos-detail-comment</h1>

app.js state多级嵌套的设置为

复制代码
var photoGallery = angular.module('photoGallery',["ui.router"]);

photoGallery.config(function($stateProvider, $urlRouterProvider){
    $urlRouterProvider.otherwise('home');

    $stateProvider
        .state('content',{
            url: '/',
            views:{
                "":{templateUrl: 'partials/content.html'},
                "header@content":{templateUrl: 'partials/header.html'},
            }
        })
        .state('content.home',{
            url: 'home',
            views:{
                "body@content":{templateUrl: 'partials/home.html'}
            }
        })
        .state('content.photos',{
            url: 'photos',
            views:{
                "body@content":{templateUrl: 'partials/photos.html'}
            }
        })
        .state('content.photos.list',{
            url: '/list',
            templateUrl: 'partials/photos-list.html'
        })
        .state('content.photos.detail',{
            url: '/detail',
            templateUrl: 'partials/photos-detail.html'
        })
        .state('content.photos.detail.comment',{
            url: '/comment',
            templateUrl: 'partials/photos-detail-comment.html'
        })
        .state('content.about',{
            url:'about',
            views:{
                "body@content":{templateUrl: 'partials/about.html'}
            }
        })
})
复制代码

 

■ 抽象state

如果一个state,没有通过链接找到它,那就可以把这个state设置为abstract:true,我们把以上的content和content.photos这2个state设置为抽象。

 

复制代码
.state('content',{
    url: '/',
    abstract: true,
    views:{
        "":{templateUrl: 'partials/content.html'},
        "header@content":{templateUrl: 'partials/header.html'},
    }
})
...


.state('content.photos',{
    url: 'photos',
    abstract: true,
    views:{
        "body@content":{templateUrl: 'partials/photos.html'}
    }
})
复制代码

 

那么,当一个state设置为抽象,如果通过ui-sref或路由导航到该state会出现什么结果呢?

--会导航到默认路由上

$urlRouterProvider.otherwise('home');

即

 

.state('content.home',{
    url: 'home',
    views:{
        "body@content":{templateUrl: 'partials/home.html'}
    }
})

 

最终把partials/home.html显示出来。

 

■ 使用控制器

在实际项目中,数据大多从controller中来。

首先在路由中设置state所用到的控制器以及控制器别名。

 

复制代码
var photoGallery = angular.module('photoGallery',["ui.router"]);

photoGallery.config(function($stateProvider, $urlRouterProvider){
    $urlRouterProvider.otherwise('home');

    $stateProvider
        .state('content',{
            url: '/',
            abstract: true,
            views:{
                "":{templateUrl: 'partials/content.html'},
                "header@content":{templateUrl: 'partials/header.html'},
            }
        })
        .state('content.home',{
            url: 'home',
            views:{
                "body@content":{
                    templateUrl: 'partials/home.html',
                    controller: 'HomeController',
                    controllerAs: 'ctrHome'
                }
            }
        })
        .state('content.photos',{
            url: 'photos',
            abstract: true,
            views:{
                "body@content":{
                    templateUrl: 'partials/photos.html',
                    controller: 'PhotoController',
                    controllerAs: 'ctrPhoto'
                }
            }
        })
        .state('content.photos.list',{
            url: '/list',
            templateUrl: 'partials/photos-list.html',
            controller: "PhotoListController",
            controllerAs: 'ctrPhotoList'
        })
        .state('content.photos.detail',{
            url: '/detail',
            templateUrl: 'partials/photos-detail.html',
            controller: 'PhotoDetailController',
            controllerAs: 'ctrPhotoDetail'
        })
        .state('content.photos.detail.comment',{
            url: '/comment',
            templateUrl: 'partials/photos-detail-comment.html'
        })
        .state('content.about',{
            url:'about',
            views:{
                "body@content":{templateUrl: 'partials/about.html'}
            }
        })
})
复制代码

 

添加controller.js,该文件用来定义所用到的controller.现在的文件结构为:


asserts/
.....css/
.....images/
..........image1.jpg
..........image2.jpg
..........image3.jpg
..........image4.jpg
node_modules/
partials/
.....about.html
.....home.html
.....photos.html
.....content.html
.....header.html
.....photos-list.html
.....photo-detail.html
.....photos-detail-comment.html
app.js
index.html

controllers.js

复制代码
photoGallery.controller('HomeController',['$scope', '$state', function($scope, $state){
    this.message = 'Welcome to the Photo Gallery';
}]);

//别名:ctrPhoto
photoGallery.controller('PhotoController',['$scope','$state', function($scope, $state){
    this.photos = [
        { id: 0, title: 'Photo 1', description: 'description for photo 1', imageName: 'image1.jpg', comments:[
            {name: 'user1', comment: 'Nice'},
            { name:'User2', comment:'Very good'}
        ]},
        { id: 1, title: 'Photo 2', description: 'description for photo 2', imageName: 'image2.jpg', comments:[
            { name: 'user2', comment: 'Nice'},
            { name:'User1', comment:'Very good'}
        ]},
        { id: 2, title: 'Photo 3', description: 'description for photo 3', imageName: 'image3.jpg', comments:[
            {name: 'user1', comment: 'Nice'}
        ]},
        { id: 3, title: 'Photo 4', description: 'description for photo 4', imageName: 'image4.jpg', comments:[
            {name: 'user1', comment: 'Nice'},
            { name:'User2', comment:'Very good'},
            { name:'User3', comment:'So so'}
        ]}
    ];

    //给子state下controller中的photos赋值
    this.pullData = function(){
        $scope.$$childTail.ctrPhotoList.photos = this.photos;
    }
}]);

//别名:ctrPhotoList
photoGallery.controller('PhotoListController',['$scope','$state', function($scope, $state){
    this.reading = false;
    this.photos = new Array();

    this.init = function(){
        this.reading = true;
        setTimeout(function(){
            $scope.$apply(function(){
                $scope.ctrPhotoList.getData();
            });
        }, 1500);
    }

    this.getData = function(){

        //调用父state中controller中的方法
        $scope.$parent.ctrPhoto.pullData();

        /*this.photos = $scope.$parent.ctrPhoto.photos;*/
        this.reading = false;

    }
}]);


//别名:ctrPhotoDetail
photoGallery.controller('PhotoDetailController',['$scope', '$state', function($scope,$state){

}]);
复制代码

 

以上,通过$scope.$$childTail.ctrPhotoList在父state中的controller中拿到子state中的controller;通过$scope.$parent.ctrPhoto在子state中的controller中拿到父state中的controller。

 

photos-list.html

复制代码
<h1>photos-list</h1>
<div ng-init="ctrPhotoList.init()">
  <div style="margin:auto; width: 40px;" ng-if="ctrPhotoList.reading">
    <i class="fa fa-spinner fa-5x fa-pulse"></i>
  </div>

  <div class="well well-sm" ng-repeat="photo in ctrPhotoList.photos">
    <div class="media">
      <div class="media-left" style="width:15%;">
        <a ui-sref="content.photos.detail">
          <img class="img-responsive img-rounded" src="../asserts/images/{{photo.imageName}}" alt="">
        </a>
      </div>
      <div class="media-body">
        <h4 class="media-heading">{{photo.title}}</h4>
        {{photo.description}}
      </div>
    </div>
  </div>
</div>
复制代码

 


■ state间如何传路由参数

在content.photos.detail这个state设置接收一个路由参数。

 

复制代码
.state('content.photos.detail',{
    url: '/detail/:id',
    templateUrl: 'partials/photos-detail.html',
    controller: 'PhotoDetailController',
    controllerAs: 'ctrPhotoDetail'
})
复制代码

 

photos-list.html 送出一个路由参数

复制代码
<h1>photos-list</h1>
<div ng-init="ctrPhotoList.init()">
  <div style="margin:auto; width: 40px;" ng-if="ctrPhotoList.reading">
    <i class="fa fa-spinner fa-5x fa-pulse"></i>
  </div>

  <div class="well well-sm" ng-repeat="photo in ctrPhotoList.photos">
    <div class="media">
      <div class="media-left" style="width:15%;">
        <a ui-sref="content.photos.detail({id:photo.id})">
          <img class="img-responsive img-rounded" src="../asserts/images/{{photo.imageName}}" alt="">
        </a>
      </div>
      <div class="media-body">
        <h4 class="media-heading">{{photo.title}}</h4>
        {{photo.description}}
      </div>
    </div>
  </div>
</div>
复制代码

以上,通过<a ui-sref="content.photos.detail({id:photo.id})">把路由参数送出。



controller.js PhotoDetailController控制器通过$stateParams获取路由参数

复制代码
...
//别名:ctrPhotoDetail
photosGallery.controller('PhotoDetailController', ['$scope', '$state', '$stateParams',
    function($scope, $state, $stateParams){

        var id = null;
        this.photo = null;
        this.init = function(){
            id = parseInt($stateParams.id);
            this.photo = $scope.ctrPhoto.photos[id];
        }

    }
]);
复制代码

 

photos-detail.html 从以上的PhotoDetailController中获取数据。

复制代码
<h1>photo-details</h1>
<a class="btn btn-default" ui-sref=".comment">通过相对路径去子state</a>
<a ui-sref="content.photos.list" style="margin-left: 15px;">
  <i class="fa fa-arrow-circle-left fa-2x"></i>
</a>

<div ng-init="ctrPhotoDetail.init()">
  <img class="img-responsive img-rounded" ng-src="../assets/images/{{ctrPhotoDetail.photo.imageName}}"
       style="margin:auto; width: 60%;">
  <div class="well well-sm" style="margin:auto; width: 60%; margin-top: 15px;">
    <h4>{{ctrPhotoDetail.photo.title}}</h4>
    <p>{{ctrPhotoDetail.photo.description}}</p>
  </div>

  <div style="margin:auto; width: 80%; margin-bottom: 15px;">
    <button style="margin-top: 10px; width:100%;"
            class="btn btn-default" ui-sref=".comment">Comments</button>
  </div>
</div>


<div ui-view></div>
复制代码

 

■ state间如何传字符串参数

在路由中这样设置:

 

复制代码
.state('content.photos.detail.comment',{
    url:'/comment?skip&limit',
    templateUrl: 'partials/photos-detail-comment.html',
    controller: 'PhotoCommentController',
    controllerAs: 'ctrPhotoComment'
})
复制代码

 

controllers.js 中修改如下

复制代码
photoGallery.controller('HomeController',['$scope', '$state', function($scope, $state){
    this.message = 'Welcome to the Photo Gallery';
}]);

//别名:ctrPhoto
photoGallery.controller('PhotoController',['$scope','$state', function($scope, $state){
    this.photos = [
        { id: 0, title: 'Photo 1', description: 'description for photo 1', imageName: 'image1.JPG', comments:[
            { name:'User1', comment: 'Nice', imageName: 'man.png'},
            { name:'User2', comment:'Very good', imageName: 'man.png'},
            { name:'User3', comment:'Nice', imageName: 'woman.png'},
            { name:'User4', comment:'Very good', imageName: 'woman.png'},
            { name:'User5', comment:'Very good', imageName: 'man.png'},
            { name:'User6', comment:'Nice', imageName: 'woman.png'},
            { name:'User7', comment:'So so', imageName: 'man.png'}
        ]},
        { id: 1, title: 'Photo 2', description: 'description for photo 2', imageName: 'image2.JPG', comments:[
            { name:'User1', comment: 'Nice', imageName: 'man.png'},
            { name:'User2', comment:'Very good', imageName: 'man.png'},
            { name:'User3', comment:'Nice', imageName: 'woman.png'},
            { name:'User4', comment:'Very good', imageName: 'woman.png'}
        ]},
        { id: 2, title: 'Photo 3', description: 'description for photo 3', imageName: 'image3.JPG', comments:[
            { name:'User1', comment: 'Nice', imageName: 'man.png'},
            { name:'User2', comment:'Very good', imageName: 'man.png'},
            { name:'User3', comment:'Nice', imageName: 'woman.png'},
            { name:'User4', comment:'Very good', imageName: 'woman.png'},
            { name:'User5', comment:'Very good', imageName: 'man.png'},
            { name:'User6', comment:'Nice', imageName: 'woman.png'},
            { name:'User7', comment:'So so', imageName: 'man.png'}
        ]},
        { id: 3, title: 'Photo 4', description: 'description for photo 4', imageName: 'image4.JPG', comments:[
            { name:'User6', comment:'Nice', imageName: 'woman.png'},
            { name:'User7', comment:'So so', imageName: 'man.png'}
        ]}
    ];

    //给子state下controller中的photos赋值
    this.pullData = function(){
        $scope.$$childTail.ctrPhotoList.photos = this.photos;
    }
}]);

//别名:ctrPhotoList
photoGallery.controller('PhotoListController',['$scope','$state', function($scope, $state){
    this.reading = false;
    this.photos = new Array();

    this.init = function(){
        this.reading = true;
        setTimeout(function(){
            $scope.$apply(function(){
                $scope.ctrPhotoList.getData();
            });
        }, 1500);
    }

    this.getData = function(){

        //调用父state中controller中的方法
        $scope.$parent.ctrPhoto.pullData();

        /*this.photos = $scope.$parent.ctrPhoto.photos;*/
        this.reading = false;

    }
}]);


//别名:ctrPhotoDetail
photoGallery.controller('PhotoDetailController', ['$scope', '$state', '$stateParams',
    function($scope, $state, $stateParams){

        var id = null;
        this.photo = null;
        this.init = function(){
            id = parseInt($stateParams.id);
            this.photo = $scope.ctrPhoto.photos[id];
        }

    }
]);


photoGallery.controller('PhotoCommentController', ['$scope', '$state', '$stateParams',
    function($scope, $state, $stateParams){
        var id, skip, limit = null;
        this.comments = new Array();

        this.init = function(){
            id = parseInt($stateParams.id);
            var photo = $scope.ctrPhoto.photos[id];


            if($stateParams.skip){
                skip = parseInt($stateParams.skip);
            }else{
                skip = 0;
            }

            if($stateParams.limit){
                limit = parseInt($stateParams.limit);
            }else{
                limit = photo.comments.length;
            }

            this.comments = photo.comments.slice(skip, limit);

        }
    }
]);
复制代码

也就是,$stateParams不仅可以接收路由参数,还可以接收查询字符串参数。



photo-detail.html 需要把查询字符串参数传递出去

复制代码
<h1>photo-details</h1>
<a class="btn btn-default" ui-sref=".comment">通过相对路径去子state</a>
<a ui-sref="content.photos.list" style="margin-left: 15px;">
  <i class="fa fa-arrow-circle-left fa-2x"></i>
</a>

<div ng-init="ctrPhotoDetail.init()">
  <img class="img-responsive img-rounded" ng-src="../assets/images/{{ctrPhotoDetail.photo.imageName}}"
       style="margin:auto; width: 60%;">
  <div class="well well-sm" style="margin:auto; width: 60%; margin-top: 15px;">
    <h4>{{ctrPhotoDetail.photo.title}}</h4>
    <p>{{ctrPhotoDetail.photo.description}}</p>
  </div>

  <div style="margin:auto; width: 80%; margin-bottom: 15px;">
    <button style="margin-top: 10px; width:100%;"
            class="btn btn-default" ui-sref=".comment({skip:0, limit:2})">Comments</button>
  </div>
</div>


<div ui-view></div>
复制代码

以上,通过ui-sref=".comment({skip:0, limit:2})把查询字符串传递出去。

 

photos-detail-comment.html

复制代码
<h1>photos-detail-comment</h1>

<div ng-init="ctrPhotoComment.init()" style="margin-top:15px;">
  <div ng-repeat="comment in ctrPhotoComment.comments" class="well well-sm" style="margin: auto; width: 60%;">
    <div class="media">
      <div class="media-left media-middle">
        <a href="">
          <img class="img-circle" style="width:60px;" src="../assets/images/{{comment.imageName}}" alt="">
        </a>
      </div>
      <div class="media-body">
        <h4 class="media-heading">{{comment.name}}</h4>
        {{comment.comment}}
      </div>
    </div>
  </div>
</div>
复制代码

 

■ state间如何传递对象

通过data属性,把一个对象赋值给它。

 

复制代码
.state('content',{
    url: '/',
    abstract: true,
    data:{
        user: "user",
        password: "1234"
    },
    views:{
        "":{templateUrl: 'partials/content.html'},
        "header@content":{templateUrl: 'partials/header.html'},
    }
})
复制代码

 

给header.html加上一个对应的控制器,并提供注销方法。

复制代码
$stateProvider
    .state('content',{
        url: '/',
        abstract: true,
        data:{
            user: "user",
            password: "1234"
        },
        views:{
            "":{templateUrl: 'partials/content.html'},
            "header@content":{
                templateUrl: 'partials/header.html',
                controller: function($scope, $rootScope, $state){
                    $scope.logoff = function(){
                        $rootScope.user = null;
                    }
                }
            }
        }
    })
复制代码

 

添加一个有关登录页的state

复制代码
.state('content.login',{
    url:'login',
    data:{
        loginError: 'User or password incorrect.'
    },
    views:{
        "body@content" :{
            templateUrl: 'partials/login.html',
            controller: function($scope, $rootScope, $state){
                $scope.login = function(user, password, valid){
                    if(!valid){
                        return;
                    }

                    if($state.current.data.user === user && $state.current.data.password === password){
                        $rootScope.user = {
                            name: $state.current.data.user
                        }

                        // Or Inherited

                        /*$rootScope.user = {
                            name: $state.$current.parent.data.user
                        };*/

                        $state.go('content.home');                            
                    }else{
                        $scope.message = $state.current.data.loginError;
                    }

                }
            }
        }
    }

})
复制代码

 

添加login.html文件,现在的文件结构为:

asserts/
.....css/
.....images/
..........image1.jpg
..........image2.jpg
..........image3.jpg
..........image4.jpg
node_modules/
partials/
.....about.html
.....home.html
.....photos.html
.....content.html
.....header.html
.....photos-list.html
.....photo-detail.html
.....photos-detail-comment.html
.....login.html
app.js
index.html

login.html

复制代码
<form name="form" ng-submit="login(user, password, form.$valid)">
    <div class="panel panel-primary" style="width:360px; margin: auto;">
        <div class="panel-heading">
            <h3 class="panel-title">Indentification</h3>
        </div>
        <div class="panel-body">
            <input name="user" type="text" class="form-control" ng-model="user" placeholder="User ..." required>
            <span ng-show="form.user.$error.required && form.user.$dirty" class="label label-danger">Enter the user</span>
            <hr>
            <input name="password" type="password" class="form-control" ng-model="password" placeholder="Password ..." required>
            <span ng-show="form.password.$error.required && form.password.$dirty" class="label label-danger">Enter the password</span>            
        </div>
        <div class="panel-footer">
            <button class="btn btn-default" type="submit">Login</button>
            <button class="btn btn-default" type="reset">Reset</button>
            <span class="label label-danger">{{message}}</span>            
        </div>    
    </div>
</form>
复制代码

 

header.html 修改如下

复制代码
<nav class="navbar navbar-inverse">
      <div class="container-fluid">
        <div class="navbar-header">
          <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">            
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" ui-sref="content.home">Home</a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
                <li>
                    <a ui-sref="content.photos.list">Photos</a>    
                </li>
                <li>
                    <a ui-sref="content.about">About</a>    
                </li> 
          </ul>
            <ul class="nav navbar-nav navbar-right">                
                <li ng-if="user.name" class="dropdown">
                    <a class="dropdown-toggle" role="button" aria-expanded="false" href="#" data-toggle="dropdown">{{user.name}} <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a ui-sref="content.home" ng-click="logoff()">Sing out</a></li>                        
                    </ul>                    
                </li>                                
                <li ng-if="!user.name">
                    <a ui-sref="content.login">Sing In</a>
                </li>                    
            </ul>    
        </div>
      </div>
    </nav>
复制代码

 

■ onEnter和onExit事件

 

复制代码
.state('content.photos.detail',{
    url: '/detail/:id',
    templateUrl: 'partials/photos-detail.html',
    controller: 'PhotoDetailController',
    controllerAs: 'ctrPhotoDetail',
    resolve:{
        viewing: function($stateParams){
            return{
                photoId: $stateParams.id
            }
        }
    },
    onEnter: function(viewing){

        var photo = JSON.parse(sessionStorage.getItem(viewing.photoId));
        if(!photo){
            photo = {
                views: 1,
                viewing: 1
            }
        }else{
            photo.views = photo.views + 1;
            photo.viewing = photo.viewing + 1;
        }

        sessionStorage.setItem(viewing.photoId, JSON.stringify(photo));

    },
    onExit: function(viewing){
        var photo = JSON.parse(sessionStorage.getItem(viewing.photoId));
        photo.viewing = photo.viewing - 1;
        sessionStorage.setItem(viewing.photoId, JSON.stringify(photo));
    }
})
复制代码

 

在PhotoDetailController中:

复制代码
photoGallery.controller('PhotoDetailController', ['$scope', '$state', '$stateParams',
    function($scope, $state, $stateParams){

        var id = null;
        this.photo = null;
        this.viewObj = null;
        this.init = function(){
            id = parseInt($stateParams.id);
            this.photo = $scope.ctrPhoto.photos[id];
            this.viewObj = JSON.parse(sessionStorage.getItem($stateParams.id));
        }

    }
]);
复制代码

 

photos-detail.html

复制代码
<h1>photo-details</h1>
<a class="btn btn-default" ui-sref=".comment">通过相对路径去子state</a>
<a ui-sref="content.photos.list" style="margin-left: 15px;">
  <i class="fa fa-arrow-circle-left fa-2x"></i>
</a>

<div ng-init="ctrPhotoDetail.init()">
  <img class="img-responsive img-rounded" ng-src="../assets/images/{{ctrPhotoDetail.photo.imageName}}"
       style="margin:auto; width: 60%;">
  <div class="well well-sm" style="margin:auto; width: 60%; margin-top: 15px;">
    <div class="well well-sm pull-right" style="width: 100px;">
      <i>Views <span class="badge">{{ctrPhotoDetail.viewObj.views}}</span></i>
    </div>
    <div class="well well-sm pull-right" style="width: 110px;">
      <i>Viewing <span class="badge">{{ctrPhotoDetail.viewObj.viewing}}</span></i>
    </div>

    <h4>{{ctrPhotoDetail.photo.title}}</h4>
    <p>{{ctrPhotoDetail.photo.description}}</p>
  </div>

  <div style="margin:auto; width: 80%; margin-bottom: 15px;">
    <button style="margin-top: 10px; width:100%;"
            class="btn btn-default" ui-sref=".comment({skip:0, limit:2})">Comments</button>
  </div>
</div>


<div ui-view></div>
复制代码

 

■ StateChangeStart事件



controller.js 增加如下

复制代码
photoGallery.controller('RootController', ['$scope', '$state', '$rootScope',
    function($scope, $state, $rootScope){
        $rootScope.$on('$stateChangeStart',
            function(event, toState, toParams, fromState, fromParams){
                if(toState.data.required && !$rootScope.user){
                    event.preventDefault();
                    $state.go('content.login');
                }
            });

    }
]);
复制代码

 

修改content这个state:

复制代码
.state('content',{
    url:'/',
    abstract: true,
    data:{
        user: "user",
        password: "1234"
    },
    views:{
        "":{
            templateUrl: 'partials/content.html',
            controller: 'RootController'
        },
        "header@content":{
            templateUrl: 'partials/header.html',
            controller: function($scope, $rootScope, $state){
                $scope.logoff = function(){
                    $rootScope.user = null;
                }
            }
        }
    }

})
复制代码

 

content.photos.detail这个state

复制代码
    .state('content.photos.detail',{
        url:'/detail/:id',
        templateUrl: 'partials/photos-detail.html',
        controller: 'PhotoDetailController',
        controllerAs: 'ctrPhotoDetail',
        data:{
            required: true
        },
        resolve:{
            viewing: function($stateParams){
                return{
                    photoId: $stateParams.id
                }
            }
        },
        onEnter: function(viewing){
            
            var photo = JSON.parse(sessionStorage.getItem(viewing.photoId));
            if(!photo){
                photo = {
                    views: 1,
                    viewing: 1
                }
            }else{
                photo.views = photo.views + 1;
                photo.viewing = photo.viewing + 1;
            }
            
            sessionStorage.setItem(viewing.photoId, JSON.stringify(photo));
            
        },
        onExit: function(viewing){
            var photo = JSON.parse(sessionStorage.getItem(viewing.photoId));
            photo.viewing = photo.viewing - 1;
            sessionStorage.setItem(viewing.photoId, JSON.stringify(photo));
        }
    })
复制代码

 

   
以上,添加了        
data:{
    required: true
}    


同理,content.photos.detail.comment这个state

 

复制代码
.state('content.photos.detail.comment',{
        url:'/comment?skip&limit',
        templateUrl: 'partials/photos-detail-comment.html',
        controller: 'PhotoCommentController',
        controllerAs: 'ctrPhotoComment',
        data:{
            required: true
        }
    })
复制代码

 


■ StateNotFound事件

 

复制代码
photosGallery.controller('RootController', ['$scope', '$state', '$rootScope',
            function($scope, $state, $rootScope){
                
                $rootScope.$on('$stateChangeStart', 
                function(event, toState, toParams, fromState, fromParams){
                    
                    if(toState.data.required && !$rootScope.user){
                        event.preventDefault();
                        $state.go('content.login');
                        return;
                    }    
                    
                });
                
                $rootScope.$on('$stateNotFound', 
                function(event, unfoundState, fromState, fromParams){
                    event.preventDefault();
                    $state.go('content.notfound');
                });
            }
]);
复制代码

 

添加一个state:

    .state('content.notfound',{
        url:'notfound',
        views: {
            "body@content": {templateUrl: 'partials/page-not-found.html'}    
        }        
    })

 


page-not-found.html

<div class="well well-sm" style="margin: 20px;">
    <i class="fa fa-frown-o fa-4x pull-left"></i><h3>404 - Sorry! Not found your page.</h3>
</div>

 

■ StateChangeSuccess事件

 

复制代码
photosGallery.controller('RootController', ['$scope', '$state', '$rootScope',
            function($scope, $state, $rootScope){
                
                $rootScope.accessLog = new Array();
                
                $rootScope.$on('$stateChangeStart', 
                function(event, toState, toParams, fromState, fromParams){
                    
                    if(toState.data.required && !$rootScope.user){
                        event.preventDefault();
                        $state.go('content.login');
                        return;
                    }    
                    
                });
                
                $rootScope.$on('$stateNotFound', 
                function(event, unfoundState, fromState, fromParams){
                    event.preventDefault();
                    $state.go('content.notfound');
                });
                
                $rootScope.$on('$stateChangeSuccess', 
                function(event, toState, toParams, fromState, fromParams){
                    $rootScope.accessLog.push({
                        user: $rootScope.user,
                        from: fromState.name,
                        to: toState.name,
                        date: new Date()
                    });
                });
                
            }
]);
复制代码

 

添加一个state

复制代码
    .state('content.log',{
        url:'log',
        data:{
            required: true
        },
        views: {
            "body@content": {templateUrl: 'partials/log.html'}    
        }        
    })
复制代码

 

log.html

复制代码
<h1><i class="fa fa-file-text-o"></i> Access Log</h1>
<div style="margin:auto; width: 380px;">
    <div class="well well-sm" ng-repeat="log in accessLog track by $index">
        <i class="fa fa-pencil fa-2x pull-left"></i>
        {{log.user ? log.user.name: 'anonymous'}} in {{log.date | date: 'longDate'}} at {{log.date | date: 'shortTime'}}
        <p>From: {{log.from}} => to: {{log.to}}</p>
    </div>
</div>
复制代码

 


■ StateChangeError事件

 

复制代码
photosGallery.controller('RootController', ['$scope', '$state', '$rootScope',
            function($scope, $state, $rootScope){
                
                $rootScope.accessLog = new Array();
                
                $rootScope.$on('$stateChangeStart', 
                function(event, toState, toParams, fromState, fromParams){
                    
                    if(toState.data.required && !$rootScope.user){
                        event.preventDefault();
                        $state.go('content.login');
                        return;
                    }    
                    
                });
                
                $rootScope.$on('$stateNotFound', 
                function(event, unfoundState, fromState, fromParams){
                    event.preventDefault();
                    $state.go('content.notfound');
                });
                
                $rootScope.$on('$stateChangeSuccess', 
                function(event, toState, toParams, fromState, fromParams){
                     $rootScope.accessLog.push({
                         user: $rootScope.user,
                         from: fromState.name,
                         to: toState.name,
                         date: new Date()
                     });
                });
                
                $rootScope.$on('$stateChangeError', 
                function(event, toState, toParams, fromState, fromParams, error){
                    event.preventDefault();
                    $state.go('content.error', {error: error});
                });
                
            }
]);
复制代码

 

添加2个state:

复制代码
    .state('content.profile', {
        url:'profile',
        data:{
            required: true
        },
        resolve:{
            showError: function(){
                throw 'Error in code.';
            }
        },
        views:{
            "body@content": {template: '<div>Error</div>'}
        }    
    })
    
 .state('content.error',{
        url:'error/:error',
        views:{
            "body@content":{
                templateUrl: 'partials/error.html',
                controller: function($scope, $stateParams){
                    $scope.error = {
                        message: $stateParams.error
                    }
                }
            }
        }
    })   
复制代码

 

error.html

<div class="well well-sm" style="margin: 20px;">
    <i class="fa fa-exclamation-circle fa-2x"> Sorry! But this message was displayed: {{error.message}}</i>
</div>

 

ui-router使用教程 ui-router使用教程,实现frameset效果,不跳转页面的情况下,实现页面内部局部跳转,须有对angularJs有一定的了解 立即下载

相关推荐

Pulpino SoC中挂载AXI从机接口的自定义IP说明

AXI 从机接口挂载 Pulpino SoC 调试Pulpino SoC中挂载AXI从机接口的自定义IP说明PULPion SoC介绍自定义AXI IP挂载IP挂载框图代码修改脚本修改自定义AXI IP调试C语言编写软件调试硬件调试 Pulpino SoC中挂载AXI从机接口的自定义IP说明 本篇文章主要从工程的角度描述了如何将具有AXI从机接口的自定义IP挂载到Pulpino SoC上,其中不涉及到SoC中的任何原理知识。 PULPion SoC介绍 PULPion SoC整体架构如下图所示, PULPi

小陈的芯片学习之路 2211

深入理解ANGULARUI路由_UI-ROUTER

http://blog.eisneim.com/articles/dive_deep_into_ui-router.html AngularJS不需要任何第三方库,利用自身集成的各个模块便可开发出功能齐全的web应用,不过活跃的AngularJS社区也开发了很多能够最大限度强化web应用的编程库。本文带读者了解专业开发使用的模块AngularUI中的ui-路由(ui-router)。

SalmonellaVaccine的专栏 2451

Windows 11下用Ollama一键部署DeepSeek-R1大模型(附8B/14B版本选择建议)

本文详细介绍了在Windows 11环境下使用Ollama工具一键部署DeepSeek-R1大模型的完整指南,包括8B和14B版本的选择建议。通过硬件评估、安装配置、性能优化等步骤,帮助开发者高效实现本地部署,提升AI应用体验。

weixin_29079643的博客 272

AngularJs ui-router 路由的简单介绍

之前有写过一篇关于Angular自带的路由:ngRoute。今天来说说Angular的第三方路由:ui-router。那么有人就会问:为什么Angular有了自带的路由,我们还需要用ui-router呢?这里简单明了的说明下ngRoute和ui-router的区别吧,其实也没很大的区别,主要的就是ngRoute针对于单视图,而ui-router可用于多视图(这里说的视图是指在页面内我们可控制的,可...

weixin_34290352的博客 402

XGBoost的简单安装及入门使用

XGBoost安装及简单入门 XGBoost支持多种操作系统,如Windows, Linux, MacOS等,并支持多种语言版本,如Python, R, Scale, Java等。XGBoost的安装方式一般有两种,一种是直接通过pip安装(适合用于Python),另外一种是通过源码编译安装 1、通过pip安装 通过pip安装Python包既简单又方便,只需执行如下的命令: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xgboost 使用

qq_41513230的博客 3万+

安装matlab_Matlab+yalmip+cplex安装教程及算例

数学建模/科研学习推荐学习软件:Matlab+yalmip+cplex安装教程及算例其实绝大多数本科生都是在用Matlab和LINGO求解优化问题,Matlab可以求解一般优化问题,但是当优化问题规模比较大或者在应对一些非线性问题时候,Matlab会出现求解时间长,求解效率低,甚至难以求解等问题。Matlab+yalmip+cplex是Matlab通过调用商业软件cplex求解,求解时间短,这里简...

weixin_28939637的博客 5006

Angular-Ui-Router

Angular-ui-router

ssegrub的博客 4939

基于DSP28335的Matlab/Simulink代码生成实验七:A/D采样

实验七:讲解如何使用DSP的ADC模块,通过代码生成技术控制DSP进行电流采样,是后续实现电机闭环控制的重要环节。通过简单的实验来熟悉代码生成的过程。最终实现复杂算法代码自动生成,进行高性能电机控制!

m0_73869369的博客 4724

Automa 工作流分享与下载完全指南:从发布到团队权限一次讲清

你刚在 Automa 里拼好一个用来自动采集数据的 Automa 工作流,同事说他也想跑一份。与其发截图让他一块积木一块积木地重搭,不如点一下"分享"按钮,把链接发过去。反过来,想从社区下载并导入别人写好的工作流模板,流程也并不更复杂。这份指南按"你发布 → 对方接收"的顺序,把分享、团队权限、下载导入整条链路走一遍,顺带把常见的坑提前标出来。 ## 先花一分钟搞懂:Automa 工作流是什么

gitblog_00003的博客 498

QT实现ftp服务器(附完整源码)

QT实现ftp服务器(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 1783

Python 爬虫进阶技巧:新手必学的反爬突破与效率优化

本文系统总结了爬虫进阶的核心技巧,针对新手常见的反爬拦截、效率低下、动态页面解析等痛点问题,提出了可落地的解决方案。主要内容包括:通过随机UA池、代理IP池和Cookie池突破常见反爬机制;利用多线程/异步请求提升爬取效率;使用Selenium解析动态渲染页面;以及数据清洗方法提升数据质量。文中提供了完整的代码示例和实战对比数据,并强调爬虫开发应遵守合规性要求。这些技巧能帮助开发者快速提升爬虫实战能力,应对80%以上的常见爬取需求。

2503_91057718的博客 1436

angular 之 ui-router路由

转自:http://yijiebuyi.com/blog/3aab7ad8bccb22b4a881849c0593d5e2.html angular.js 为我们封装好了一个路由工具 ngRoute ,它是一种靠url改变去驱动视图. angularUI 也为我们封装了一个独立的路由模块 ui-router ,它是一种靠状态 state 来驱动视图. 后者有什么优势:一个页面可以嵌套多个视...

ljx896779016的专栏 338

高通Camx功能feature分析之八:高通NCS服务之架构和初始化

本文介绍了高通NCS(NONCameraSensor)服务的架构与初始化流程。NCS服务通过QMI接口访问非相机传感器,为CameraEIS、AEC等算法节点提供陀螺仪、加速度计等传感器数据支持。文章详细解析了NCS服务的分层架构,包括客户端、服务端、QSEE接口实现等组件,并重点分析了初始化过程中获取传感器列表、查询能力等关键步骤。通过camxsetting.xml中的enableNCSService开关控制服务启动,初始化过程涉及QSEE单例创建、传感器能力查询等核心操作。后续文章将继续深入讲解相关技术

930

Angularjs中UI Router全攻略

http://www.jb51.net/article/78895.htm 首先给大家介绍angular-ui-router的基本用法。 如何引用依赖angular-ui-router ? 1 2 3 4 angular.module('app',["ui.router"]) .config(function($statePro

XINGXUEXX的博客 1005

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

angularjsl路由_angularjs中的路由介绍详解 ui-route

这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧首先给大家介绍angular-ui-router的基本用法。如何引用依赖angular-ui-router$stateProvider.state(stateName, stateConfig)stateName是string类型stateConfig是obje...

weixin_39695954的博客 240

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

angularjs中的路由介绍详解 ui-route(转)

http://www.cnblogs.com/littlemonk/p/5500801.html 这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧 首先给大家介绍angular-ui-router的基本用法。 如何引用依赖angular-ui-router angular.module('app',["ui...

weixin_34336292的博客 214

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

angularjs中的路由介绍详解 ui-route

这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧 首先给大家介绍angular-ui-router的基本用法。 如何引用依赖angular-ui-router ? 1 2 3 4 angular.module('app',["ui...

weixin_30716141的博客 145

AngularJS进阶(一)深入理解ANGULARUI路由_UI-ROUTER_angularjs ui-router

抽象模板不能被激活,但是它的子模板可以被激活。抽象模板可以提供一个包括了多个有名的视图的模板,或者它可以传递作用域变量$scope给子模板。使用它可以在同一个url下传递自定义数据或者预载入的依赖。})})});

2401_84437604的博客 1125

angular-ui-router 多视图views

angular-ui-router APIUI Router 中有三种方式激活一个路由: (1)$state.go():优先级较高的便利方式 (2)ui-sref:点击包含此指令跳转 (3)url:url导航一、$state.go()(1)$state.go(to [, toParams] [, options]) 参数: to:绝对“state名称”或者相对的“state路径”(如果路径

李刚的学习专栏 3万+

angular路由的深入理解

最近在用 ionic写个webapp 看到几个demo中路由有好几种,搞的有点晕,查下资料研究下,做个笔记,其中大部分为摘抄别人的,做个说明免得被人吐槽。Angularjs ui-router - 组件: state/state / stateProvider:管理状态定义、当前状态和状态转换。包含触发状态转换的事件和回调函数,异步解决目标状态的任何依赖项,更新location到当前状态。由于状态包

IT_caainiao的博客 666

angularjs ui-router详解

1:首先为什么选择ui-router,而没有选择ng-router 最主要的原因是ui-router路由可以多层路由嵌套 具体用法 1:首先引入这个插件 2:如何使用路由 1:首先全局注入路由模块 angular.module('mainApp',['ul.router']) 2:开始使用 首先,配置路由 angular.module('mainApp',['ui....

ygy211715的博客 2322

Angularjs之ui-router的简单实用

1.介绍 ui-router ui-router被认为是AngularUI为开发者提供的最实用的一个模块,它是一个让开发者能够根据URL状态或者说是’机器状态’来组织和控制界面UI的渲染,而不是仅仅只改变路由(传统AngularJS应用实用的方式)。该模块为开发者提供了很多最视图(view)额外的控制。开发者可以创建嵌套分层的视图、在同一个页面使用多个视图、让多个视图控制某个视图等更多的功能。即使...

小猪快跑 605
上一篇: AngularJS去掉URL中的 # 号
下一篇: equals()和“==”的区别
雕花の刺猬
博客等级 码龄10年 45粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值