我正在嘗試構建一個簡單的應用程序。如何調試角路由?
我的index.html文件
<!DOCTYPE html>
<html>
<head>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-route/angular-route.js"></script>
<script src="/js/main.js"></script>
<script src="/js/controllers/account.js"></script>
</head>
<body ng-app="elara">
wuuuu
<div ng-view></div>
</body>
</html>
main.js文件
var app = angular.module('elara', [
'ngRoute'
]);
app.config(['$routeProvider',
function($routeProvider) {
debugger;
$routeProvider.
when('/', {
templateUrl: '/html/template/home-page.html',
controller: 'accountController'
}).
otherwise({
redirectTo: '/phones'
});
}]);
和我的控制器:
var app = angular.module('elara', []);
app.controller('accountController', ['$scope', '$http', function(){
$scope.username = "";
$scope.password = "";
$scope.register = function(){
$http.post(config.apiAddress + "account/login/", {username: $scope.username, password: $scope.password}).then(
function(data){
console.log(data);
}, function(response){
console.log(response);
});
};
}]);
請noitice在main.js文件中的調試器,但degugger目前還沒有停止。它看起來不像執行我的app.config函數中的內容。當瀏覽到/
路線,我家page.html中未裝入ng-view
順便說一句,你忘了參數'$ scope'和'$ http'給控制器。 –