This example is about listing all functions and objects in $scope. $scope is also one Javascript object. By listing key value pairs of $scope, we can list down all functions and objects.
Example Code
Here functionArray, varArray arrays are variables and fun1 is function. We have to list them in same types.
$scope.functionArray = []; $scope.varArray = []; $scope.fun1 = function() { };
Code to List Down Functions And Variables
Here key represents name of variable or function. We can verify functions with angular.isFunction and objects or variables with angular.isObject
$scope.listFunAndVar = function() { var obj = $scope; for (var key in obj) { if (obj.hasOwnProperty(key)) { if (angular.isFunction(obj[key])) { $scope.functionArray.push(key); } else if (angular.isObject(obj[key])) { $scope.varArray.push(key); } } } };
Default $scope objects
AngularJS defines some objects to $scope. Those are "this","$$listeners","$$listenerCount","$parent","$$watchers"
0 comments:
Post a Comment