I am trying to disable a button based on an angular object array being empty. My HTML below..
<ons-button ng-click="do stuff" ng-disabled="testFunc()">Add</ons-button>
This is inside an ng-app HTML and inside of a controller. My test function is below...
$scope.objs = [];
$scope.testFunc = function() {
if($scope.objs == null) {
return true;
}
else {
return false;
}
};
I have my function and the $scope.objs = [];
declared inside the controller, and the button is not being disabled. Am I doing something wrong?
EDIT: Appears the function is not even firing, will ng-disabled not fire once DOM is loaded. Also, could there be an issue with declaring the array and maybe it wasnt declared intime for the function to test it? Should I add an OR testing if its undefined
?
$scope.objs
is an array, which is different than null
. Try to check its length
instead...
if($scope.objs.length === 0) {
return true;
}
else {
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.