错误:我的浏览器中的$ injector:modulerr模块错误

时间:2016-08-27 21:44:13

标签: angularjs

我是AngularJS的新手,我正在尝试运行这个AngularJS,它应修改URL而不重新加载页面,但控制台显示未捕获错误:[$ injector:modulerr]

问题出在哪里?

var app = angular.module("SearchAPP", ['ng-route']);

app.run(['$route', '$rootScope', '$location',
  function($route, $rootScope, $location) {
    var original = $location.path;
    $location.path = function(path, reload) {
      if (reload === false) {
        var lastRoute = $route.current;
        var un = $rootScope.$on('$locationChangeSuccess', function() {
          $route.current = lastRoute;
          un();
        });
      }
      return original.apply($location, [path]);
    };
  }
]);

app.controller('GetController', ['$http', '$scope', '$location',
  function($http, $scope, $rootScope, $location) {

    $scope.click = function() {

      var response = $http({
        url: 'http://localhost:4567/search',
        method: "GET",
        params: {
          keyword: $scope.searchKeyword
        }
      });

      response.success(function(data, status, headers, config) {
        $scope.searchResults1 = data;
        // $http.defaults.useXDomain = true;
        $location.path('/' + $scope.searchKeyword, false);
      });

      response.error(function(data, status, headers, config) {
        alert("Error.");
      });
    };
  }
]);

1 个答案:

答案 0 :(得分:1)

附加angualar-route.js并使用ngRoute代替ng-route

var app = angular.module("SearchAPP", ['ngRoute']);