2016-08-27 4 views
0

AngularJS를 처음 사용하고 페이지를 다시로드하지 않고 URL을 수정해야하는 AngularJS를 실행하려고하지만 콘솔에 Uncaught Error : [$ 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

angualar-route.js를 부착하고 ng-route

var app = angular.module("SearchAPP", ['ngRoute']); 
대신 ngRoute를 사용
관련 문제