zoukankan      html  css  js  c++  java
  • angular-ui-router速学

    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

  • 相关阅读:
    iOS 倒计时及获取本时区时间
    文字上的删除线
    ios 预览文件-QLPreviewController用法
    iOS delegate、notification、KVO的区别
    mvc 详解
    app切图暂时没有iOS8的,后续继续添加
    背影图
    字体渐变
    ios for 循环 创建 九宫格
    Spherical Harmonics Lighting
  • 原文地址:https://www.cnblogs.com/mafeifan/p/6572403.html
Copyright © 2011-2022 走看看