Easy Money
Easy Money

Reputation: 527

ng-click Button function with Angularjs

I have found this demo in (jsfiddle), One thing I am not sure is the okay button they have

<button ng-click="activity.isEdited = false">Ok</button>

With this function, I am wondering if we can still add a function inside the ng-click? with something like this?

<button ng-click="domeSomthing()">Ok</button>

Can we include both activity.isEdited = false and domeSomthing()inside the ng-click?

Upvotes: 0

Views: 39

Answers (3)

Strelok
Strelok

Reputation: 51481

Why not have a scope function that does both?

function doSomething() {
    alert('Done editing');
}
$scope.editedActivity = function(activity) {
    activity.isEdited = false;
    doSomething();
}

and in HTML

<button ng-click="editedActivity(activity)">Ok</button>

Fiddle: http://jsfiddle.net/A5xZ9/4/

Upvotes: 2

jonode
jonode

Reputation: 797

Sure can!

Just add your function to the controllers scope or to a directive. Then you can call it in the ng-click. To use both the function and the Boolean just separate them with a semi-colon

Upvotes: 1

Matt Herbstritt
Matt Herbstritt

Reputation: 4862

Try:

<button ng-click="activity.isEdited = false; domeSomthing();">Ok</button>

Upvotes: 1

Related Questions