Reputation: 7083
if selectedOwners
length is >
0
i want to set selectedOwnerDisplay
falg true when page initially load it is set to false. For addOwner
its working good but for deleteOwner
its not hiding grid when selectedOwners
length is<
0
.
Any idea what is wrong with below code ?
Any better way to implement these conditions ?
main.html
<div class="col-md-12">
<div kendo-grid="selectedOwner" ng-show="selectedOwnerDisplay" k-options="selectedOwnerGridOptions" k-rebind="selectedOwnerGrid"></div>
</div>
ctrl.js
var selectedOwners = [];
$scope.selectedOwnerDisplay = false;
$scope.deleteOwner = function(dataItem) {
angular.forEach(selectedOwners, function(owner, $index) {
if (owner.workerKey === dataItem.workerKey) {
selectedOwners.splice($index, 1);
}
});
if(selectedOwners.length < 0){
$scope.selectedOwnerDisplay = false;
}
}
$scope.addOwner = function(dataItem){
if(selectedOwners.length > 0){
$scope.selectedOwnerDisplay = true;
}
};
Upvotes: 0
Views: 74
Reputation: 558
You eat your angular in wrong way :)
You should't try to check selectedOwnerDisplay, just use
ng-show="selectedOwners.length"
and, of course, set selectedOwners in scope.
Upvotes: 1
Reputation: 16172
The array length can not be less than zero, you probably need this:
if (selectedOwners.length === 0) { // or selectedOwners.length < 1
$scope.selectedOwnerDisplay = true;
}
Upvotes: 1