如何從$scope.Profile.address
對象中刪除一個對象,請幫我看看下面的代碼和圖像
<tr ng-repeat="x in Profile.addresses">
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.site_name ' name='site_name'></td>
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.street_address ' name='street_address'></td>
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.city ' name='city'></td>
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.state ' name='state'></td>
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.country ' name='country'></td>
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.zip_code ' name='zip_code'></td>
<td><input type="text" class="form-control" id="inputDefault" ng-model='x.phone_number ' name='phone_number'></td>
<td><a href="" data-toggle="tooltip" title="Remove Address" ng-click="removeAddress(x.addresses)"><i class="fa fa-close text-danger" aria-hidden="true"></i></a></td>
</tr>
JS
$scope.removeAddress = function(address) {
var index = $scope.Profile.addresses.indexOf(address);
if (index != -1)
$scope.Profile.addresses.splice(index, 1);
console.log($scope.Profile.addresses);
};
所以你有你的代碼有任何錯誤?我認爲你正試圖刪除你的數組中的dup –
你試過用'delete $ scope.Profile.address'嗎? – manzapanza
我想從我的數組中刪除一個對象我正在顯示html –