美文网首页前端学习笔记
angularJS中的ui-router和ocLazyLoad使

angularJS中的ui-router和ocLazyLoad使

作者: 简小咖 | 来源:发表于2018-05-07 16:08 被阅读48次

    在angularJs中,index.html 引入

    <body ng-controller="AppCtrl">
      <div class="app" id="app" ui-view>
    </div>
    </body>
      <!-- Angular -->
    <script src="angular.min.js"></script>
    
      <!-- Vendor -->
    <script src="angular-ui-router.js"></script>
    
      <!-- lazyload -->
    <script src="ocLazyLoad.js"></script>
    
    

    router.js

    var app = angular.module('myApp',
     ['oc.lazyLoad', 'ui.router']);
    //配置路由  
    app.config(function ($stateProvider, $urlRouterProvider) {
        $urlRouterProvider
            .otherwise('/app/questionList'); //默认页面
        //首页  
        $stateProvider.state('app', {
            // abstract: true,
            url: '/app',
            templateUrl: 'src/home.html'
        })
        //二级页面
        .state('app.questionList', {
            url: '/questionList',
            templateUrl: '/questionList.html',
            resolve: {
                deps: ['$ocLazyLoad',
                  function( $ocLazyLoad ){
                    return $ocLazyLoad.load(['/questionList.js']);
                }]
              }
        })
        .state('app.questionAdd', {
            url: '/questionAdd',
            templateUrl: '/questionAdd.html',
            resolve: {
                deps: ['$ocLazyLoad',
                  function( $ocLazyLoad ){
                    return $ocLazyLoad.load(['/questionAdd.js']);
                }]
              }
        })   
    });  
    
    

    nav.html

     <ul class="nav nav-sub dk">
              <li ui-sref-active="active">
                <a ui-sref="app.questionList">
                  <span>列表</span>
                </a>
              </li>
              <li ui-sref-active="active">
                <a ui-sref="app.questionAdd">
                  <span>添加</span>
                </a>
              </li>  
            </ul>
          </li>
        </ul>
    

    home.html

    <div ng-include="'nav.html'"></div>
    <!-- content -->
    <div class="app-content">
        <div class="app-content-body fade-in-up" ui-view></div>
    </div>
    

    页面效果


    image.png

    相关文章

      网友评论

        本文标题:angularJS中的ui-router和ocLazyLoad使

        本文链接:https://www.haomeiwen.com/subject/byhvrftx.html