AngualrJs路由

JS代码:

// Define `myApp` module
var app = angular.module('myApp', ['ui.router']);
//声明把$stateprovider路由引擎作为函数参数传人,为应用程序配置路由
app.config(function($stateProvider , $urlRouterProvider) {
    $urlRouterProvider.when("", "/home");
    $stateProvider
        .state("home", {
            url: "/home",
            views: {
                "": {
                    template: "<h1>HELLO!</h1>"
                },
                "test": {
                    templateUrl:'http://localhost:8080/king/userController/display2',
                }
            }
        })
        .state('page1', { 
            url: '/Page1',
            templateUrl:'http://localhost:8080/king/userController/display2',
            controller: function($scope, $state) {
                $scope.change = function() {
                    $state.go('detail');
                }
            }
        })
        .state('detail', { 
            url: '/detail',
            templateUrl:'../static/views/nestedViews/htmls/1/detail.html',
            controller: function($scope, $state) {
                    $scope.change = function() {
                        $state.go('1');
                    }
                }
        })
        .state('page2', {
            url: '/Page2',
            templateUrl: '../static/views/nestedViews/htmls/2/Page2.html',
            controller: function($scope, $state) {
                $scope.change = function() {
                    $state.go();
                }
            }
        })
        .state('page3', {
            url: '/Page3',
            templateUrl: '../static/views/nestedViews/htmls/3/Page3.html',
        })
        .state('3.child', {
        views: {
            'A' : {
                templateUrl:'../static/views/nestedViews/htmls/3/a.html'
            },
            'B' : {
                templateUrl:'../static/views/nestedViews/htmls/3/b.html'
            }
        }
        })
});
app.controller('MainController', function($scope , $http) {
    $scope.ulList = [
        {
            sref: "page1",
            name: "我的页",
        },
        {
            sref: "page2",
            name: "第二页",
        },
        {
            sref: "page3",
            name: "第三页",
        }
    ];
    $scope.headName = "老詹的小破酒馆";
    $scope.titleName = "小詹的篮球梦";
});

app.directive("header",function(){
    return{
        restrict: 'EAC',
        transclude: true,
        templateUrl:'../static/views/nestedViews/htmls/pa/head.html'
    }
});
app.directive("nav",function(){
    return{
        restrict: 'EAC',
        transclude: true,
        templateUrl:'../static/views/nestedViews/htmls/pa/nav.html'
    }
});
app.directive("footer",function(){
    return{
        restrict: 'EAC',
        transclude: true,
        templateUrl:'../static/views/nestedViews/htmls/pa/footer.html'
    }
});

html:

<body ng-controller="MainController">
        <!--头部  -->
        <header></header>
        <!--左侧栏  -->
        <nav></nav>
        <!--主内容  -->
        <div ui-view="test"></div>
        <!--底部内容  -->
        <footer></footer>   
</body>

注意的一点是: templateUrl不能是web-inf文件夹下的。(把那些限制访问的资源(比如说jsp源代码)放到Web应用的WEB-INF目录下,对于/web-INF/及其子目录,不允许直接的公共访问,所以就可以起到保护这些代码未经授权的访问和窥视,更好的保护了源代码。)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值