javascript - How to splice variable value in AngularJS? -


how splice variable value in angularjs

html:

<div ng-repeat="steps in data" class="card" style="padding:10px 5px 10px 5px; margin-bottom:10px; margin-top:20px; background: url(@routes.assets.at("images/assets/icon_move.png")) no-repeat right #fafbfc; background-position : calc(100% - 10px) 50%;">     {{steps.title}}     <div class="pull-right"  ng-click="deletestep(steps);"  style="color:#f26063; padding-right: 40px;">delete</div>     <a class="pull-right" ng-click="openaddstep('lg');" style="color:#43c944; padding-right: 20px;">edit</a> </div> 

javascript:

$scope.deletestep = function(steps){     alert('h');     (var = $scope.steps.length - 1; >= 0; i--) {         if (!$scope.steps[i].value) {             $scope.steps.splice(i, 1);         }     } } 

you can pass current index delete method , splice below, option find index of data object using indexof method , splice it

<div class="pull-right"  ng-click="deletestep($index);"  style="color:#f26063; padding-right: 40px;">delete</div> 

js

$scope.deletestep = function(index){                         $scope.data.splice(index, 1);                     } 

var app = angular.module('my-app', [], function() {})    app.controller('appcontroller', function($scope) {      $scope.data = [];    (var = 0; < 10; i++) {      $scope.data.push({        title: 'title: ' +      });    }      $scope.deletestep = function(index) {      $scope.data.splice(index, 1);    }    $scope.deletestep2 = function(steps) {      $scope.data.splice($scope.data.indexof(steps), 1);    }  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>    <div ng-app="my-app">    <div ng-controller="appcontroller">      <div ng-repeat="steps in data" class="card" style="padding:10px 5px 10px 5px; margin-bottom:10px; margin-top:20px;">        {{steps.title}}        <div class="pull-right" ng-click="deletestep($index);" style="color:#f26063; padding-right: 40px;">delete</div>        <div class="pull-right" ng-click="deletestep2(steps);" style="color:#f26063; padding-right: 40px;">delete 2</div>        <a class="pull-right" ng-click="openaddstep('lg');" style="color:#43c944; padding-right: 20px;">edit</a>      </div>        </div>  </div>


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -