2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var NAVSERVICE_CONSTANT = require('./nav-service');
var ngTableDoc = angular.module('ngTableDoc', ['ui.router', 'ngMessages'])
    .config([
        'NAVSERVICE',
        '$stateProvider',
        '$urlRouterProvider',
        function (NAVSERVICE, $stateProvider, $urlRouterProvider) {
            $urlRouterProvider.otherwise("/docs/api/");
            $stateProvider
                .state('api', {
                    url:'/docs/api/:doc',
                    views:{
                        'navigation':{
                            templateUrl:'partials/nav.html',
                            controller:'NavController'
                        },
                        'content':{
                            templateUrl: function($stateParams){
                                return $stateParams.doc ? $stateParams.doc : 'partials/api/ngTable/index.html';
                            }
                        }
                    }
                })
                // note: runnable examples are not yet implemented (instead we link to external demo site)
                .state('examples',{
                    url:'/docs/api/examples',
                    templateUrl:'/partials/examples/'
                });
        }
    ]).run(function($rootScope, NavStateService){
        $rootScope.$on('$stateChangeSuccess', function(event, toState){
            NavStateService.setView(toState.name);
            console.log('Switched state to', toState.name)
        });
    })
    .factory('NavStateService', function(){
        //default state
        var navState = "gettingStarted";
        return{
            getView:function(){
                return navState;
            },
            setView:function(viewName){
                navState = viewName
            }
        }
    })
    .controller('MainController', function ($scope) {
        $scope.vm = {};
    })
    .controller('NavController', function ($scope,$location, NAVSERVICE, NavStateService) {
        var model = {};
        var currentView = NavStateService.getView();
        model.navigation = NAVSERVICE.filter(function(navItem){
            return currentView === navItem.name
        });
        model.navigation = model.navigation[0];
        $scope.vm = model;
    });
 
ngTableDoc.constant('NAVSERVICE', NAVSERVICE_CONSTANT.data);