app.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. angular
  2. .module('app', ['ng', 'ngRoute', 'appView'])
  3. .config(function ($httpProvider, $routeProvider, $locationProvider) {
  4. $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  5. $routeProvider
  6. .when('/', {
  7. controller: 'IndexController',
  8. templateUrl: 'app/views/index/index.tpl.html'
  9. })
  10. .when('/list', {
  11. controller: 'ListController',
  12. templateUrl: 'app/views/list/list.tpl.html'
  13. });
  14. $routeProvider.otherwise({ redirectTo: '/' }); // 未找到指定的路由地址,重定向到home页
  15. $locationProvider.html5Mode({
  16. enabled: true,
  17. requireBase: false
  18. });
  19. })
  20. .run(function ($rootScope, $location) {
  21. /* 监听路由的状态变化 */
  22. $rootScope.$on('$routeChangeStart', function (event, next, current) {
  23. console.log('route begin change');
  24. });
  25. $rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
  26. console.log('route have already changed :' + $location.path());
  27. });
  28. })
  29. .controller('AppController', function () {
  30. console.log('Application Loaded!');
  31. });