I have two functions inside my controller
$scope.first = function()
{
console.log("first");
}
$scope.second = function()
{
console.log("hello");
}
Now in my template i give call to first function
<button ng-click="first()">click</button>
Now I want that as soon as my first function complete its execution, automatically my second function starts executing without any click.
That is on single click first function executes and then second function executes respectively.
Just call the functions separated by ;
<button ng-click="first();second()">click</button>
Or you can do:
function first() {
// Do stuff
}
function second() {
// Do stuff
}
$scope.runBoth = function () {
first();
second();
}
The good thing with that approach is that you can listen to first() return and based on that run/skip execution of second() etc.
Also by keeping first() and second() as just javascript functions you are not adding unnecessary watchers (assuming that you're not using first() and second() somewhere else).
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