ui-router搭建的angularjs模板

目录结构如图




index.html文件

<!DOCTYPE html>
<html ng-app="shopApp">
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="plugin/bootstrap-3.0.0/css/bootstrap.my.min.css"/>
    <link rel="stylesheet" href="public/css/base.css"/>
    <script src="plugin/js/angular-1.3.0.js"></script>
    <script src="plugin/js/angular-ui-router.js"></script>
    <script src="public/js/app.js"></script>
    <script src="public/js/controllers.js"></script>
    <script src="public/js/controllers1.js"></script>
    <script src="public/js/directives.js"></script>
    <script src="public/js/filters.js"></script>
    <script src="public/js/services.js"></script>
</head>
<body>
<div ui-view></div>
</body>
</html>

app.js

var shopApp = angular.module('shopApp', [
  'ui.router',
  'shopControllers',
  'shopFilters',
  'shopDirectives',
  'shopServices'
]);

var shopApp = angular.module('shopApp1', [
    'ui.router',
    'shopControllers',
    'shopFilters',
    'shopDirectives',
    'shopServices'
]);
shopApp.config(['$stateProvider','$urlRouterProvider',function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/index');
    $stateProvider.state('index', {
        url: "/index",
        views: {
            '': {
                templateUrl: 'tpls/index.html'
            },
            'nav@index': {
                templateUrl: 'tpls/public_nav.html'
            },
            'main@index': {
                templateUrl: 'tpls/index_home.html'
            }
        }
    }).state('index.search', {
        url: '/search',
        views: {
            'main@index': {
                templateUrl: 'tpls/index_search.html'
            }
        }
    }).state('index.shoping', {
        url: '/shoping',
        views: {
            'main@index': {
                templateUrl: 'tpls/index_shoping.html'
            }
        }
    }).state('index.my', {
        url: '/my',
        views: {
            'main@index': {
                templateUrl: 'tpls/index_my.html'
            }
        }
    }).state('datails', {
        url: '/datails/:id',
        templateUrl: 'tpls/datails.html'
    })
}]);

页面传值index_home.html页面进入详情页

<div class="box" ng-controller="commodityListCtrl">
    <div class="por_list line_bottom" ng-repeat="vo in commodity">
        <a ui-sref="datails({id:{{vo.id}}})">
            <div class="list_box">
                <div class="por_img">
                    <img ng-src="{{vo.img}}">
                </div>
                <div class="por_name">
                    {{vo.title}}
                </div>
            </div>
        </a>
    </div>
</div>
<div class="clearfix"></div>


controllers.js

var shopControllers = angular.module('shopControllers', ["qqqCtrl"]);
//列表页
shopControllers.controller('commodityListCtrl', ['$scope', '$http',
    function ($scope, $http) {
        $http.get('json/pro.json').success(function (data) {
            $scope.commodity = data;
        });
    }
]);
//详情页
shopControllers.controller('datailsCtrl', ['$scope','$stateParams', '$http',
    function ($scope,$stateParams, $http) {
        $http.get('json/'+$stateParams.id+'.json').success(function (data) {
            $scope.commodity = data;
        });
    }
]);

directives.js

var shopDirectives = angular.module("shopDirectives",[]);

shopDirectives.directive('hello', function() {
    return {
        restrict: 'E',
        template: '<div>Hi there</div>',
        replace: true
    };
});


filters.js

var shopFilters = angular.module('shopFilters', []);

shopFilters.filter('checkmark1', function() {
  return function(input) {

  };
});

services.js

var shopServices = angular.module('shopServices', []);

shopServices.factory('Phone', ['$resource',
  function($resource){

  }]);


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值