1

Can I execute few actions by using one ng-click attribute? For example:

<input type="button" ng-click="createUser(); isVisiblePopup = true" value="Create new user">

Also I tried to use arrow function:

<input type="button" ng-click="createUser(); () => { isVisiblePopup = true }" value="Create new user">

5 Answers 5

1

You can create a method createUserHandler() to handle the click event:

Html:

<input type="button" ng-click="createUserHandler()" value="Create new user">

JavaScript:

$scope.createUserHandler= function() {
    $scope.isVisiblePopup = true;
    $scope.createUser(); 
}
Sign up to request clarification or add additional context in comments.

Comments

1

<input type="button" ng-click="function () { functionCall1(); functionCall2(); etc } .. could do the trick for what you need. or having an other named function that get called that does the same as above for readability

Comments

1

You can call your subsequent instructions inside the main one:

createUser = function () {
    isVisiblePopup = true;
    ...
}

Alternatively, if you really insist, you can call multiple functions by separating them with a ;

Working fiddle: http://jsfiddle.net/y1z29mqy/

2 Comments

Yes I know but I find more elegant way. createUser function is resposible for creating users not for displaying popup.
You should usually try to avoid putting logic in the html: logic belongs in the controller. Maybe createUser() is wrongly named?
1

The first version

<input type="button" ng-click="createUser(); isVisiblePopup = true" value="Create new user">

looks good. What is your actual problem? Maybe its not working for another reason.

Comments

0

I would create a action doAll which calls all methods and sets all values you want in that one click.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.