<div ng-controller="signupCtrl">
<ul class="list-group" >
<li class="list-group-item">
<div class="form-group">
<input type="text" ng-model="signupCtrl.firstName">
</div>
...
</div>
<div class="form-group">
<div class="pull-right">
<button ng-click="signupCtrl.signupUser()">Register</button>
</div>
</div>
</li>
</ul>
</div>
someAppControllers.controller('signupCtrl', [
'$window',
'$scope',
'HttpReqHandlerService',
'$location',
'localStorageService'],
function($window, $scope, HttpReqHandlerService,
$location, localStorageService) {
$scope.signupUser=function signupUser() {
alert("hello");
}]);
该按钮未在我的控制器中调用signupUser函数
答案 0 :(得分:8)
使用$scope.signupUser
代替this.signupUser
将代码更改为
someAppControllers.controller('signupCtrl', ['$window', '$scope',
function ($window, $scope) { // Here you have to define function an pass window and scope
$scope.signupUser = function signupUser() {
alert("hello");
};
}
]);
此外,您还有语法错误。
HTML 的
而不是
<input type="text" ng-model="signupCtrl.firstName">
<button ng-click="signupCtrl.signupUser()">Register</button>
使用
<input type="text" ng-model="firstName">
<button ng-click="signupUser()">Register</button>
答案 1 :(得分:4)
您已经编写了标记,就好像使用了controller as
语法一样。要使其有效,只需将ng-controller="signupCtrl"
更改为ng-controller="signupCtrl as signupCtrl"
;