为什么下面的输入按钮不调用控制器login()
内的功能InitCtrl
?
<html lang="en" ng-app="mvc-module" class="ng-scope"><head>
<meta charset="utf-8">
<title>Sign in</title>
<script src="/SpringMVC/static/todo.js"></script>
</head>
<body>
<div ng-controller="InitCtrl" ng-bind-html-unsafe="mainPage" class="ng-scope ng-binding">
<!------ this part of code is injected by binding model of Angularjs -->
<div class="container">
<input type="button" ng-click="login()" value="Sign in" class="btn btn-large btn-primary">
</div>
<!--- end of injection --->
</div>
</body></html>
这是todo.js
:
function InitCtrl($scope, $http) {
$scope.login = function () {
console.log("In login!");
$http.post("login", {password: $scope.password, username: $scope.username}).
success(function (data, status, headers, config) {
$scope.mainPage = data;
console.log("successfully logged to login");
}).error(function (data, status, headers, config) {
console.log("error in post");
});
};
$http.get("login").success(function (data, status, headers, config) {
$scope.mainPage = data;
});
}
这不是问题的提琴手版本http://jsfiddle.net/pooyaho/M8krc/4/