我想一次单击即可执行两个功能,但未执行。
当我尝试单独执行它们时,它工作正常。
我使用分号'分隔两个函数名称; '。
这是我的代码:
<!DOCTYPE html>
<html>
<body ng-app="starter" ng-controller="NavCtrl">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic head</h1>
</ion-header-bar>
<ion-content>
<h4>Enter the details</h4>
<div class="list list-inset" >
<label class="item item-input">
<input type="text" name="place" ng-model="data.place" value="" placeholder="Place">
</label>
<label class="item item-input">
<input type="number" name="pincode" ng-model="data.pincode" value="" placeholder="Pin Code">
</label>
<button class="button button-block button-positive" ng-click="savedata(); navigat('/success.html')" >
Submit
</button>
</div>
</ion-content>
</ion-pane>
</body>
</html>
这是控制器代码:
app.controller('NavCtrl',function($scope,$location,$http,$window){
$scope.data = {};
$scope.savedata = function(){
$http.post("http://localhost/angular/insert2.php",{'place':$scope.data.place,'pincode':$scope.data.pincode})
.success(function(data,status,headers,config){
//console.log(data);
alert("successful");
})
.error(function(){
alert("failed");
})
};
$scope.navigat = function(url){
$window.location.href=url;
};
$scope.submit = function(){
$scope.savedata();
//$scope.navigat('/success.html');
// $window.location.href='/success.html';
}
});
我还尝试调用Submit函数,该函数调用其他两个函数-savedata()和navigat()-,但它仅调用一个函数。
我还尝试将这两个函数放在两个不同的控制器中,然后在按钮元素之前在body元素上调用一个控制器,在div元素上调用另一个控制器。但是看起来它甚至没有加载一个控制器。
请帮忙
最佳答案
你可以尝试一下:
app.controller('NavCtrl',function($scope,$location,$http,$window){
$scope.data = {};
$scope.savedata = function(){
$http.post("http://localhost/angular/insert2.php",{'place':$scope.data.place,'pincode':$scope.data.pincode})
.success(function(data,status,headers,config){
//console.log(data);
alert("successful");
$scope.navigat('/success.html');
})
.error(function(){
alert("failed");
})
};
$scope.navigat = function(url){
$window.location.href=url;
};
$scope.submit = function(){
$scope.savedata();
//$scope.navigat('/success.html');
// $window.location.href='/success.html';
}
});