0
これはHTML形式です。私は編集ボタンをクリックすると、フォームに戻るようにエントリを配置する必要があります。それはスクリプト関数に指示します。selectEdit()TypeError:未定義のプロパティ 'fname'を読み取ることができません
<div ng-app="MyApp" ng-controller="mainController">
<div class=container>
<form ng-submit="addItem()" name="myForm">
<br>
<br>
<br>
<br>
<h1> Add Member </h1>
<div class="form-group">
<div class="col-xs-3">
<input type="text" placeholder="first name" ng-model="fname" required class="form-control"
> <br>
<input type="text" placeholder="last name" ng-model="lname" required class="form-control"> <br>
<input type="email" placeholder="Email" ng-model="email" name="myEmail" class="form-control"> <br>
<span ng-show="myForm.myEmail.$error.email"> Not a Valid Email Address </span>
<input type="number" placeholder="contact number" ng-model="contact" required class="form-control"> <br>
<input type="text" placeholder="address" ng-model="addres" required class="form-control"> <br>
<input type="submit" value ="Submit">
</div>
</div>
</form>
</div>
<div class="container">
<h1> Address Book </h1>
<hr>
<table class= "table table-hover" > <br> <br>
<tr>
<th>Name </th>
<th>Email </th>
<th>Contact Number </th>
<th>Address</th>
<th>Options</th>
</tr>
<tr>
<th><input type="text" ng-model="searchFname" placeholder="search"> </th>
<th><input type="text" ng-model="searchEmail" placeholder="search"> </th>
<th><input type="text" ng-model="searchContact" placeholder="search"> </th>
<th><input type="text" ng-model="searchAddress" placeholder="search"> </th>
<th><input type="text" disabled="sfd" > </th>
</tr>
<tr ng-repeat="x in address | orderBy: 'fname' | filter:{fname:searchFname, email:searchEmail, contact:searchContact, addres:searchAddress}">
<td> {{x.fname + " " + x.lname}} </td>
<td> {{x.email}} </td>
<td> {{x.contact}} </td>
<td> {{x.addres = $index}} </td>
<td> <input type="button" value="edit" ng-click="selectEdit($index)"> | <input type ="button" value="delete" ng-click="remove($index)"></td>
</tr>
</table>
</div>
</div>
問題はフォームにエントリを戻せないということです。私が持っているvar list = $scope.address[chenes];
:それエラーアドレスアレイはchenes
が含まれていないと思われます未定義
<script type="text/javascript">
var app = angular.module("MyApp", []);
app.controller("mainController", function($scope) {
$scope.x = [];
$scope.address= [];
$scope.fname = "";
$scope.lname = "";
$scope.email = "";
$scope.contact = "";
$scope.addres = "";
$scope.addItem = function() {
$scope.address.push({
fname: $scope.fname,
lname: $scope.lname,
email: $scope.email,
contact: $scope.contact,
addres: $scope.addres
});
$scope.fname = "";
$scope.lname = "";
$scope.email = "";
$scope.contact = "";
$scope.addres = "";
};
$scope.remove = function(index) {
var isConfirmed = confirm("Are you sure to delete this record?");
if(isConfirmed) {
$scope.address.splice(index,1);
}
else {
return false;
}
};
$scope.selectEdit = function(index) {
console.log(index);
var chenes = getSelectedIndex(index);
var list = $scope.address[chenes];
$scope.fname = list.fname;
$scope.lname = list.lname;
$scope.email = list.email;
$scope.contact = list.contact;
$scope.addres = list.addres;
};
function getSelectedIndex(index){
for(var i=0; i<$scope.address.length; i++)
if($scope.address[i].index==index)
return i;
return -1;
};
});
</script>
エラーはどのラインから来ていますか? $スコープまたはリスト? – ukn
編集ボタンが選択され、$ scope.selectEdit = function(index) –
に指示されたスクリプトで、リストは次のようにして未定義です:var list = $ scope.address [chenes]; – ukn