VISHAL PRAKASH
VISHAL PRAKASH

Reputation: 49

Error: $injector:modulerr Module Error in my browser

I'm new to AngularJS and I'm trying to run this AngularJS that should modify the URL without reloading the page but the console says Uncaught Error: [$injector:modulerr]

Where is the problem?

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

Upvotes: 0

Views: 55

Answers (1)

akn
akn

Reputation: 3722

Attach angualar-route.js and use ngRoute instead of ng-route

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

Upvotes: 1

Related Questions