gpt4 book ai didi

javascript - 两个 ng-click 函数不一起执行

转载 作者:行者123 更新时间:2023-11-28 18:45:19 25 4
gpt4 key购买 nike

我想通过一次 ng-click 执行两个函数,但它没有执行。

当我尝试单独执行它们时,它工作正常。

我使用分号 ' ; 分隔两个函数名称。 '.

这是我的代码:

<!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>

这是 Controller 代码:

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';
}

});

我还尝试调用提交函数,该函数调用其他两个函数 - savedata() 和 navigat() - 但它只调用一个函数。

我还尝试将这两个函数放入两个不同的 Controller 中 - 然后在 body 元素上调用一个 Controller ,在按钮元素之前的 div 元素上调用另一个 Controller 。但看起来它甚至没有加载一个 Controller 。

请帮忙

最佳答案

你能试试这个吗:

   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';
}

});

关于javascript - 两个 ng-click 函数不一起执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35426003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com