Find element in an array using array.forEach

0

I have a grid where in each row there is a button to delete the corresponding data. This grid is fed by a json but there is no id. I would like to know how I could do to delete the selected object, the grid being fed by a ng-repeat and to delete a given I have to get the click, remove the item from the array and give a post with all the data to the server back.

Here's what I'm trying to do (and it's not working)

ng.remover = function(liberados){
    var ind;
    allow.url.forEach(function (lib, i){
        if(liberados == lib){
            ind = i;
        }
    });
    allow.url.splice(1,ind);
    var allowCopied = angular.copy(allow);      
    allowCopied.name = allowCopied.url;

    ng.tudo.allowedSitesList.push( allowCopied );
    $http({method: "POST", url: "http://localhost:0000/in", data: ng.tudo})
        .then(function (dados) {});     
}
    
asked by anonymous 25.08.2014 / 22:00

1 answer

1

I did not understand what you wanted to do in your function, but if you want to compare if it contains an item in an angled foreach, try doing this:

$scope.allow = [{"url":"google.com"}, {"url":"uol.com"}, {"url":"globo.com"}, {"url":"msn.com"}];

$scope.denied = [];

$scope.remove = function(urlLiberada){
    //chama o foreach do angular
    angular.forEach($scope.allow, function (item,index){
        //verifica se contem
        if(item.url.indexOf(urlLiberada) != -1){
            //adiciona o item a lista denied
            $scope.denied.push(item);   
            //remove da lista allow
            $scope.allow.splice(index);                  
        }
    });
}

//testando a funçao removendo a url msn.com
$scope.remove("msn.com")
    
25.08.2014 / 23:07