Javascript 从一个函数调用另一个函数并传递参数 editContact.html
参数phone_number通过函数editContact(contact.phone_number)从editContact.html传递。我想现在将其发送到函数updateContact,在这里我使用phone_number进行php调用,以使用特定的phone_number更新联系人Javascript 从一个函数调用另一个函数并传递参数 editContact.html,javascript,html,angularjs,function,Javascript,Html,Angularjs,Function,参数phone_number通过函数editContact(contact.phone_number)从editContact.html传递。我想现在将其发送到函数updateContact,在这里我使用phone_number进行php调用,以使用特定的phone_number更新联系人 我查看了服务,但不知道如何申请这种情况,如果有人能向我展示代码或建议什么不起作用,我将不胜感激?您正在$scope上设置电话号码,这意味着它将在updateContacts中提供,您的输入电话号码在哪里?嘿,
我查看了服务,但不知道如何申请这种情况,如果有人能向我展示代码或建议什么不起作用,我将不胜感激?您正在$scope上设置电话号码,这意味着它将在
updateContacts
中提供,您的输入电话号码在哪里?嘿,它正在工作,我没有意识到$scope是全局的。因此,如果我错了,请纠正我,如果在任何控制器中,您使用$scope.xx=“xx”声明了一个变量@code_ethusist$scope实际上不是全局的。它本身和任何子作用域都可以使用。如果希望它是全局的,请使用$rootScope
<h1>Select record to edit </h1>{{msg}}{{phone_number}}</br></br>
<form>
<table>
<tr>
<td>First Name: </td><td><input type="text" ng-model="firstname">
</td>
</tr>
<tr>
<td>Second Name: </td><td><input type="text" ng-model="secondname">
</td>
</tr>
<tr>
<td>Email: </td><td><input type="email" ng-model="email"></td>
</tr>
<tr>
<td>Status: </td>
<td><input type="radio" value="active" ng-model =
"status">Active</td>
<td><input type="radio" value="inactive" ng-
model="status">Inactive</td>
</tr>
<tr>
<td><input type="button" value="Submit" ng-click="updateData()" />
</tr> {{error}}
</form>
<div ng-init="displayContacts()">
<table border="1px">
<thead>
<tr>
<th>First Name</th>
<th>Second Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in data">
<td>{{contact.first_name}}</td>
<td>{{contact.second_name}}</td>
<td>{{contact.email}}</td>
<td>{{contact.phone_number}}</td>
<td>{{contact.status}}</td>
<td><button ng-
click="editContacts(contact.phone_number);">Edit</button></td>
</tr>
</tbody>
</table>
app.controller('EditController', function($scope, $http, ) {
$scope.message = 'Hello from EditController';
$scope.updateContacts = function(){
$http.post("update.php", {
'first_name':$scope.firstname,
'second_name' : $scope.secondname,
'email' : $scope.email,
'status' : $scope.status}).success(function(msg){
$scope.msg = "Data updated";
}).error(function(error){
$scope.error(error);
})
}
$scope.displayContacts = function(){
$http.get("retrieveAll.php").
success(function(data){
$scope.data = data;
})
}
$scope.editContacts = function(phone_number){
$scope.phone_number = phone_number
//var phone= phone_number;
$scope.msg = "Edit for number :";
}