I am experiencing issues with the length of an array in a condition-based scenario. The problem I am facing is that the array does not increase at the expected time. To better illustrate my issue, I have created a Plunker with sample code:
Upon clicking "push" for the second time, I would like the alert to show 'gt 1'. How can I resolve this dilemma? Perhaps by using a counter or another method?
<div ng-repeat="user in data">
<a ng-click="pushUser(user)">push</a>
</div>
app.controller('MainCtrl', function($scope) {
$scope.users = [];
$scope.data = [{name: 1} ,{name: 2}, {name:3}];
$scope.pushUser = function(user) {
if($scope.users.length > 1) {
alert('gt 1');
$scope.users.push(user);
} else {
alert('lt 1');
$scope.users.push(user);
}
}
});