0
ng-repeat을 사용하여 배열을 바인딩합니다. 여기에 코드가 있습니다.
HTML :
<form>
<table>
<tr data-ng-repeat="x in names">
<td><textarea placeholder="New Name" ng-model="x.name" name="" ></textarea></td>
<td><button style="background:#f00;" ng-click="removeChoice(x)">-</button></td>
</tr>
</table>
</form>
자바 스크립트 :
.controller('TerrItemCtrl', function($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html', {
scope: $scope,
animation: 'animated bounceInDown',
hideDelay: 920
}).then(function (modal) {
$scope.names = [{ 'id': 'name1'}];
$scope.modal = modal;
$scope.modal.show();
});
$scope.removeChoice = function (x) {
for (i = 0; i < $scope.names; i++) {
if ($scope.names[i].id === x.id) {
$scope.names.splice(i);
break;
}
}
};
});
나는 html로 그것을 찾을 수없는 이런 형태의 컨트롤러에 $ scope.removeChoice 기능을 가지고있다. 나는 그것이 사용하고있는 배열 때문이라고 생각하지만 이것은 입력 태그의 오른쪽에 (-) 버튼을 넣을 수있는 유일한 방법이다. 이 방법을 우회하는 방법?
컨트롤러 코드를 추가하십시오. –
대답이 아니지만 'data-ng-repeat'이'
'$ index'와'Collection.splice (INDEX, 1)'을 사용한다고 가정하십시오 – Rayon
답변
출처
2016-10-24 09:43:34 Weedoze
이미 동일한 응답을 받았습니다 –
@KrupeshKotecha Your 's는'table' 태그 안에'ng-repeat'를 사용하고 있습니다 – Weedoze
이
출처
2016-10-24 09:39:00
ng-repeat
새로운 범위를 유도 해보십시오. 따라서 부모에 액세스 할 수는$parent.someMethodInParentScope()
이것은 겨 반복의 문서에서 분명하지 않을 수 있습니다 사용했습니다. 당신은
$rootScope
에 대한 문서를 확인했습니다 : https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$parent출처
2016-10-24 09:41:54 deostroll
시도 이것을 사용 :
출처
2016-10-24 09:43:15 Araz
이 구문은 배열로 범위를 통과 시도해야 뿐만 아니라 귀하의 기능. 문제는 함수가 실행 가능한 컨텍스트 내에서 스코프 변수를 전달하지 않을 때 발생할 수 있습니다.
출처
2016-10-24 09:45:30 Troy
관련 문제