How can I use Object.keys(obj).length in an angular Expression?
For example, this does not work:
{{Object.keys(obj).length}}
even though
{{obj}} prints out a JSON object.
One solution is to add Object.keys function to the scope :
$scope.getKeys = Object.keys;
And then in the template :
{{getKeys(obj).length}}
just curious why Object is out of scope or something
Because Object methods are not allowed in Angular expressions. Check source code for parser if you want to see what else is disallowed.
// ...
} else if (// block Object so that we can't get hold of dangerous Object.* methods
obj === Object) {
throw $parseMinErr('isecobj',
'Referencing Object in Angular expressions is disallowed! Expression: {0}',
fullExpression);
}
What you can do instead is to expose necessary method or object to the scope explicitly using $scope object.
ng-initand use it from there. just curious whyObjectis out of scope or something..