Reputation: 45
I have an angularjs controller, inside that I have method1 and method2 defined.
Now I need a way to fetch information of the defined method inside the angular controller.
I tried with the $scope variable It gives me access to the functions but what I would need here is to get all the methods defined as list(or something similar).
when I say $scope.getAllMethods
it should give me information of method1
and method2
which is defined inside the controller.
Upvotes: 1
Views: 1103
Reputation: 5049
How is this?
If they are, push to an array and stringify them.
$scope.methods = [];
$scope.getAllMethods = function() {
console.log($scope);
var props = Object.getOwnPropertyNames($scope);
for (var i = 0; i < props.length; i++) {
if (typeof($scope[props[i]]) === 'function') {
$scope.methods.push({
'name': props[i],
'function': $scope[props[i]].toString()
})
}
}
}
Upvotes: 2