0

부트 스트랩 모달을 설치 프로그램의 경고 상자로 사용하려고합니다. JSFiddle에서 코드를 실행하고 노트를 삭제하려고하면 "정의되지 않은 'splice'속성을 읽을 수 없습니다."오류가 발생합니다. Visual Studio에서 동일한 코드를 실행하면 오류가 표시되지 않지만 잘못된 메모는 삭제됩니다. 생성 된 첫 번째 노트를 삭제합니다. 주십시오 take a look at the fiddle that I created하십시오.AngularJS, Modal, "정의되지 않은 'splice'속성을 읽을 수 없습니다.

'use strict' 

var app = angular.module('plunker', ['ui.sortable','ui.bootstrap']); 

app.controller('MainCtrl', function ($scope, $modal) { 

    var i; 
    $scope.itemsList = { 
     items1: [], 
     items2: [] 
    }; 

    for (i = 0; i <= 5; i += 1) { 
     $scope.itemsList.items1.push({ 'Id': i, 'Label': 'Item ' + i }); 
    } 
    $scope.sortableOptions = { 
     containment: '#sortable-container', 
     accept: function (sourceItemHandleScope, destSortableScope) { 
      return sourceItemHandleScope.itemScope.sortableScope.$id === destSortableScope.$id; 
     } 
    }; 

    $scope.addNote = function() { 
    $scope.itemsList.items1.push({"Id" : $scope.itemsList.items1.length, "Label": "Item " +  $scope.itemsList.items1.length}) 
    } 

    $scope.alert = function() { 
     $modal.open({ 
      templateUrl: 'openAlertBox.html', 
      scope: $scope, 
      controller: function ($scope) { 
       $scope.ok = function (index) { 
        $scope.itemsList.items.splice(index, 1) 
        $scope.$dismiss(); 
       } 
       $scope.cancel = function() { 
        $scope.$dismiss() 
       } 
      } 
     }) 
    } 

}); 
<html ng-app="plunker"> 
<head> 
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script> 
    <script src="https://rawgithub.com/a5hik/ng-sortable/master/dist/ng-sortable.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> 
     <script data-require="[email protected]*" data-semver="0.10.0" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script> 
</head> 
<body ng-controller="MainCtrl"> 
    <div id="sortable-container"> 
     <div class="form-actions"> 
      <div class="input-append"> 
       <form> 

        <button class="btn btn-success" type="button" ng-click="addNote()"> 
         Add Note 
        </button> 
       </form> 
      </div> 
     </div> 
     <div class="sortable-row" as-sortable="sortableOptions" ng-model="itemsList.items1"> 
      <div ng-repeat="item in itemsList.items1" class="simpel-fighter-input" as-sortable-item> 
       <input class="category-form textboxid" type="text" name="input" ng-model="item.Label" placeholder="Deltager1"> 
       <div as-sortable-item-handle class="touch-mover">MOVE ME</div> 
       <a ng-click="alert()" href><div class="touch-mover">DELETE</div></a> 
       <input class="category-form textboxid" style="float:right" type="text" name="input" ng-model="item.Label2" placeholder="Deltager2"> 
      </div> 
     </div> 

    </div> 
</body> 
</html> 
<script type="text/ng-template" id="openAlertBox.html"> 
    <div class="modal-header"> 
     <h3 class="modal-title">You are about to delete</h3> 
    </div> 
    <div class="modal-body"> 
     <p>du you really want to delete?</p> 
    </div> 
    <div class="modal-footer"> 
     <button class="btn btn-primary" ng-click="ok()">Yes</button> 
     <button class="btn btn-warning" ng-click="cancel()">No</button> 
    </div> 
</script> 

답변

0

당신은 초기 HTML에서 인덱스를 전달해야 그것은 'ok'기능입니다.

$scope.alert = function (index) { 

} 
+0

감사합니다. 이것은 알렉스의 의견을 종합 한 것입니다. –

+0

Working Fiddle : jsfiddle.net/VJ94U/1024/ –

0

그것의 간단한, 당신은 배열 "항목을"이 없습니다 :)의 소위 "items1를"당신이 $의 scope.ok이

$scope.itemsList.items1.splice(index, 1) 
+0

안녕하세요. 알렉스, 저도 해 봤는데 이제는 삭제 작업을합니다. 그러나 그것은 잘못된 쪽지를 삭제합니다. 내가 선택한 것을 상관없이 상단 음을 삭제합니다. –

+0

Yeswanth의 의견으로 저는 당신과 같이 일했습니다. 알렉스 고마워! –

+0

당신은 오신 것을 환영합니다. –

1

당신 index 인수를 변경하는 단지 필요가 있도록 메소드가 정의되지 않았습니다. params에는 항목의 통과 색인이 필요합니다. 대신 '확인'기능을 매개 변수로 인덱스를 복용,

<a ng-click="alert($index)" href><div class="touch-mover">DELETE</div></a> 

와 $ scope.alert 기능의 기능과 사용을 경고하는 매개 변수로 인덱스를 가지고 :

관련 문제