I was using controllers like this
.controller("somename",function($scope,$http){
//some get function to fetch data
$scope.data = dataReturned;
$scope.$apply();
});
It was working fine. Then I wanted to use functions after reading johnpapa's blog and changed it to the one like below
.controller("somename",someNameController);
function someNameController(){
var someName = this;
//some get function to fetch data
this.data = dataReturned;
this.$apply();
};
but this did not work as this.$apply is not a function
When I added $scope(which is not recommended) it started working
.controller("somename",someNameController);
function someNameController($scope){
var someName = this;
//some get function to fetch data
$scope.data = dataReturned;
$scope.$apply();
};
is it possible to eliminate the passing of $scope in function someNameController($scope) ?
why do you want to skip the $scope? in order to get the reference of all the methods and variables in the controller you have to use the $scope .thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With