码迷,mamicode.com
首页 > 其他好文 > 详细

angular-ui-router速学

时间:2017-03-30 13:24:39      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:class   ref   bar   function   route   china   state   mod   strong   

Demo1

初始化

<html ng-app="app">
<head>
    <style>.active { color: red; font-weight: bold; }</style>
</head>
<ul class="nav navbar-nav">
  <li>
    <a ui-sref="home" ui-sref-active="active">Photos</a>
  </li>
  <li>
    <a ui-sref="about" ui-sref-active="active">About</a>
  </li>
</ul>    


<div ui-view>

</div>

    
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
<script>
    angular.module(‘app‘,["ui.router"])
    .config(function($stateProvider){

        let routeStates = [
            {
                name: ‘home‘,
                url: ‘/home‘,
                template: ‘<h3>home!</h3>‘
            },
            {
                name: ‘about‘,
                url: ‘/about‘,
                template: ‘<h3>about!</h3>‘
            }
        ]

        routeStates.forEach(state => {
            $stateProvider.state(state);
        })
    })

</script>
</html>

Demo2

使用controller和templateUrl属性

<script>
    angular.module(‘app‘,["ui.router"])

    .controller(‘loginController‘, function($scope) {
        $scope.name = ‘finley‘;
    })
    .config(function($stateProvider){

        let routeStates = [
            {
                name: ‘home‘,
                url: ‘/home‘,
                template: ‘<h3>home!</h3>‘
            },
            {
                name: ‘about‘,
                url: ‘/about‘,
                template: ‘<h3>about!</h3>‘
            },
            {
                name: ‘login‘,
                url: ‘/login‘,
                controller: ‘loginController‘,
                templateUrl: ‘views/login.html‘
            }
        ]

        routeStates.forEach(state => {
            $stateProvider.state(state);
        })
    })

</script>

项目代码:https://git.oschina.net/finley/angular-ui-router-demo/

参考:https://github.com/angular-ui/ui-router/wiki

 

angular-ui-router速学

标签:class   ref   bar   function   route   china   state   mod   strong   

原文地址:http://www.cnblogs.com/mafeifan/p/6572403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!