-2

here i'm using Array for avoiding duplicate data for that i wrote this code if (EmployeeList.indexOf(EmpDetails) == -1) Here im Getting Error as EmployeeList of Array is not defind

     $scope.EmployeeList = [];
        $scope.SaveDb = function (Isvalid) {
            var EmpDetails = [{
                'EmpName': $scope.EmpName,
                'Email': $scope.Email

            }]

            $scope.EmployeeList.push(EmpDetails);
            console.log($scope.EmployeeList);
        }
        }
    })

2 Answers2

0

you are pushing array into array try to push

$scope.SaveDb = function (Isvalid) {
        var EmpDetails = {
            'EmpName': $scope.EmpName,
            'Email': $scope.Email

        };
        $scope.EmployeeList .push(EmpDetails);
    }
Narek Mamikonyan
  • 4,601
  • 2
  • 24
  • 30
  • could u plz help me how can i avoid inserting duplicate data in my Array –  Nov 15 '17 at 07:05
0

You are pushing array in array and in ng-repeat you're trying to get the properties of object on array. that's the problem. Try pushing object in array and that should do the trick

 $scope.EmployeeList = [];
 $scope.SaveDb = function (Isvalid) {
    var EmpDetails = {
        'EmpName': $scope.EmpName,
        'Email': $scope.Email

    }
    $scope.EmployeeList .push(EmpDetails);
}
})
Muhammad Usman
  • 10,039
  • 22
  • 39