In AngularJS, I have 2 scope function in the controller,
$scope.fn1 = function(){ //do something A }; $scope.fn2 = function(){ //do something B //I want to call fn1 here. };
If my fn2 want to call fn1, how can I do? Thanks!
Since both functions are in the same scope you can simply call $scope. fn1() inside fn2.
If the two controller is nested in One controller. Then you can simply call: $scope. parentmethod();
The $scope in an AngularJS is a built-in object, which contains application data and methods. You can create properties to a $scope object inside a controller function and assign a value or function to it. The $scope is glue between a controller and view (HTML).
Since both functions are in the same scope you can simply call $scope.fn1()
inside fn2.
$scope.fn1 = function() { // do something A }; $scope.fn2 = function() { // do something B // I want to call fn1 here. $scope.fn1(); // this works };
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