我在angularJs中得到一些错误$ routeProvider和$ locationProvider

时间:2015-12-29 06:38:23

标签: angularjs

如何配置" locationProvider"在angularJs

var app = angular.module('app',['ngRoute','ngCookies']);
app.config(['$routeProvider' , '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
   when('/', {
     templateUrl: 'page/store-list.html',
     controller: 'storeListController'
   }).
   when('/:id', {
     templateUrl: 'page/store-details.html',
     controller: 'storeDetailController'
   }).
   otherwise({
     redirectTo: '/'
   });

    $locationProvider.html5Mode(true);
}]);

如何配置" locationProvider"在angularJs

1 个答案:

答案 0 :(得分:1)

参考此文档 路由器提供商:https://docs.angularjs.org/tutorial/step_07

var phonecatApp = angular.module('phonecatApp', [
      'ngRoute',
      'phonecatControllers'
    ]);

    phonecatApp.config(['$routeProvider',
      function($routeProvider) {
        $routeProvider.
          when('/phones', {
            templateUrl: 'partials/phone-list.html',
            controller: 'PhoneListCtrl'
          }).
          when('/phones/:phoneId', {
            templateUrl: 'partials/phone-detail.html',
            controller: 'PhoneDetailCtrl'
          }).
          otherwise({
            redirectTo: '/phones'
          });
      }]);

    app/js/controllers.js:
    var phonecatControllers = angular.module('phonecatControllers', []);
    phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http',
      function ($scope, $http) {
        $http.get('phones/phones.json').success(function(data) {
          $scope.phones = data;
        });
        $scope.orderProp = 'age';
      }]);
    phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams',
      function($scope, $routeParams) {
        $scope.phoneId = $routeParams.phoneId;
      }]);