2016-08-27 76 views
0

我是AngularJS的新手,我試圖運行這個AngularJS,它應該修改URL而無需重新加載頁面,但控制檯顯示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和使用ngRoute代替ng-route

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