Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS why returning a bool from a function is not the same as a property?

I usually return true/false from a function and pass that function into a property, but in this case it is not working.

For example:

Passing false into isEnabled works:

 $scope.myDropDownConfig = {
        allowMultiple: false,
        onSelecting: $scope.onSelect,
        isEnabled: false;
    };

This does not work:

 $scope.myDropDownConfig = {
        allowMultiple: false,
        onSelecting: $scope.onSelect,
        isEnabled: function () {
            return false;
        }
    };

Is the expression not being evaluated in time? I thought it would be the same as using a bool directly... no errors, debugger wont catch. Any ideas? Do I have to tell angular to evaluate an expression?

like image 632
Shawn J. Molloy Avatar asked Apr 16 '26 04:04

Shawn J. Molloy


1 Answers

First property is simple property and the second property is a function. So you need to invoke the second with parenthesis ()

  1. $scope.myDropDownConfig.isEnabled
  2. $scope.myDropDownConfig.isEnabled()
like image 104
Abhinav Galodha Avatar answered Apr 18 '26 17:04

Abhinav Galodha