Join the Stack Overflow Community
Stack Overflow is a community of 6.9 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
up vote 3 down vote accepted

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).

share|improve this answer
1  
of corse this will run ok, but it's easier to call both function in the ng-click – Gianmarco Dec 9 '15 at 14:25
    
It all depends on a use case. – Chris Hermut Dec 9 '15 at 14:31
1  
ok, now I see your changes, it make more sense – Gianmarco Dec 9 '15 at 17:37

Just call the functions separated by ;

<button ng-click="first();second()">click</button>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.