javascript - Angular - delete object from array completely -


i have array :

array[3] 0:object   id:7   name:"bestres3t"   profile:"rest7.png"   rate:0   restaurantcityslug:"ny"   slug:"fo4o"   __proto__:object 1:object   id:3   name:"bestrest"   profile:"rest.png"   rate:1   restaurantcityslug:"ny"   slug:"foo"   __proto__:object 2:object   id:7   name:"bestr242es3t"   profile:"re3st7.png"   rate:2   restaurantcityslug:"ny"   slug:"fo244o"   __proto__:object 

i decided remove single object (with id=3) array. i've tried delete myarray[1] did not change length of array. since ng-repeat depends on length of array makes big problem.

<li ng-repeat="(resno,restaurant) in myarray" style="margin-bottom: 20px"                 dnd-draggable="restaurant"                  dnd-effect-allowed="move"                 dnd-moved="myarray.splice($index, 1)"                 dnd-selected="myarray.selected = resno"                 dnd-callback="myarray.length"                 > 

it shows 3 list items 1 of them empty want show couple of them cause i've delete 1 of them.

any suggestion?

just try this:

    app.controller('democontroller', function($scope) {     // initial items     $scope.items = [         'item one',         'item two',         'item three'     ];      // remove item     $scope.remove = function(index) {         $scope.items.splice(index, 1);     }; }); 

html:

<div ng-controller="democontroller"> <!-- list of items button remove item --> <ul>     <li ng-repeat="item in items">          <button ng-click="remove($index)">remove</button>     </li> </ul> </div> 

look @ simple example here.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -