Thursday 17 April 2014

Get added and deleted items from array

This one is only for int array Here i am going to show how to get value of add and deleted items from defined array.


        var oldbrd = $scope.selectedDiagnosis.sort();
        var newbrd = $scope.RefferalView.Diagnosis.sort();

        var additem = [];
        var deleteitem = [];
        //var index;

        angular.forEach(oldbrd, function (value) {
            if (newbrd.indexOf(value) == -1) {
                deleteitem.push(value);
            }
        });

        angular.forEach(newbrd, function (value) {
            if (oldbrd.indexOf(value) == -1) {
                additem.push(value);
            }
        });

        $scope.AddedDiagnosisCode = additem;
        $scope.DeletedDiagnosisCode = deleteitem;
        alert('added =>: ' + additem + "_________" + 'deleted =>: ' + deleteitem);