为什么 ng-click 在示例中不起作用
Why ng-click not working in the example
我可以看到,在单击控件时,chrome 调试器不会转到控制器。我在视图和控制器中有简单的代码。另外,我没有收到任何错误。任何帮助,将不胜感激。
查看
<div class="logInBtn">
<a data-ng-click="submitLoginDetails()">
<button type="button" class="btn btn-primary">Log In</button>
</a>
</div>
控制器
app.controller('loginPageController',function($scope, $http, assimilationSurveyService){
$scope.submitLoginDetails = function(){
$scope.loginData = {
"password": "pass1234",
"userId": "userabc"
};
assimilationSurveyService.sendLoginData($scope.loginData)
.success(function(data) {
alert("Hi!");
});
}
});
路由器
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/loginPage', {title:'Feedback',templateUrl:'loginPage.html',controller:'loginPageController'})
.otherwise({title:'Feedback', templateUrl:'loginPage.html'});
}])
服务
app.service('assimilationSurveyService',function(){
return{
// For Getting expense list
sendLoginData: function(loginData) {
var sendLoginData = {
url: 'http://172.16.34.245:8080/Survey/user/login',
method: 'POST',
data: loginData,
headers: {
'Content-Type': 'application/json'
}
};
return $http(sendLoginData);
},
}
});
单击登录按钮时指针没有到达控制器。所以让我知道为什么在 ng-click 上我没有让程序进入控制器部分。
Even when I remove anchor and set the ng-click in button, I am not being redirected to controller code function. Strange issue!
答案很简单:
此视图正在默认加载,因此控制器未绑定到它。
解决方案应该是:
.otherwise({title:'Feedback', templateUrl:'loginPage.html',controller:'loginPageController'});
否则我错过了给控制器,因为这是第一个也是默认页面,所以它采取了其他方式,但由于其中没有控制器,它无法将 ng-click 连接到相应的控制器。
感谢大家的帮助...它确实帮助我调试了问题!
我可以看到,在单击控件时,chrome 调试器不会转到控制器。我在视图和控制器中有简单的代码。另外,我没有收到任何错误。任何帮助,将不胜感激。
查看
<div class="logInBtn">
<a data-ng-click="submitLoginDetails()">
<button type="button" class="btn btn-primary">Log In</button>
</a>
</div>
控制器
app.controller('loginPageController',function($scope, $http, assimilationSurveyService){
$scope.submitLoginDetails = function(){
$scope.loginData = {
"password": "pass1234",
"userId": "userabc"
};
assimilationSurveyService.sendLoginData($scope.loginData)
.success(function(data) {
alert("Hi!");
});
}
});
路由器
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/loginPage', {title:'Feedback',templateUrl:'loginPage.html',controller:'loginPageController'})
.otherwise({title:'Feedback', templateUrl:'loginPage.html'});
}])
服务
app.service('assimilationSurveyService',function(){
return{
// For Getting expense list
sendLoginData: function(loginData) {
var sendLoginData = {
url: 'http://172.16.34.245:8080/Survey/user/login',
method: 'POST',
data: loginData,
headers: {
'Content-Type': 'application/json'
}
};
return $http(sendLoginData);
},
}
});
单击登录按钮时指针没有到达控制器。所以让我知道为什么在 ng-click 上我没有让程序进入控制器部分。
Even when I remove anchor and set the ng-click in button, I am not being redirected to controller code function. Strange issue!
答案很简单:
此视图正在默认加载,因此控制器未绑定到它。
解决方案应该是:
.otherwise({title:'Feedback', templateUrl:'loginPage.html',controller:'loginPageController'});
否则我错过了给控制器,因为这是第一个也是默认页面,所以它采取了其他方式,但由于其中没有控制器,它无法将 ng-click 连接到相应的控制器。
感谢大家的帮助...它确实帮助我调试了问题!