How to call two functions when pressed in angularjs

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 completes its execution, automatically my second function starts without any clicks.

This is done the first time the first function is pressed, and then the second function is executed.

+4
source share
2 answers

Or you can do:

function first() {
    // Do stuff
}

function second() {
   // Do stuff
}

$scope.runBoth = function () {
    first();
    second();
}

The good thing with this approach is that you can listen on first () return and based on this run / skip the execution of second (), etc.

, first() second() javascript, (, first() second() - ).

+3

, ;

<button ng-click="first();second()">click</button>
+6

Source: https://habr.com/ru/post/1619214/


All Articles