0

I know about different scopes inside ng-repeat, I headed about this but I still can't solute removing of selected item of li ( I don't use $index ) instead of future sortable objects

<li class="m-1" ng-repeat="students in students.students">
  <span>{{students.student}}</span> :knowledge is - <span>{{students.knowledge}}</span>
  <button type="button" class="btn btn-danger ml-2" ng-click="students.removeItem(item)">Delete</button>
</li>

and my function working behind li-element, but delete only last element

vm.removeItem = function (item) {
  vm.students.splice(vm.students.indexOf(item), 1);
}

and I don't need $parent in ng-repeat

1 Answer 1

2

Maybe you are trying to do something like:

<li class="m-1" ng-repeat="student in students.students">
  <span>{{student.name}}</span> :knowledge is - <span>{{student.knowledge}} </span>
  <button type="button" class="btn btn-danger ml-2" ng- click="removeItem(student)">Delete</button>
</li>

$scope.removeItem = function (item) {
    this.students.students = this.students.students.filter(student => student !== item)
};

This is a working demo

Honestly, I don't understand why you have students object in students. In addition, why every item in ng-repeat is called: students?

I guess that every item needs the variable name of student.

Sign up to request clarification or add additional context in comments.

2 Comments

my code like this: codepen.io/Pavlolapan/pen/qQByWM?editors=1010 I never use codepen and it doesn't even display a arr. list
codepen.io/alonsh/pen/WYNapV?editors=1010 Please accept my answer if it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.