2015-12-29 58 views
-4

如何配置 「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

*「我得到一些錯誤..」*不可能幫助未來的讀者...請閱讀[問] –

回答

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; 
     }]);