简体   繁体   中英

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?

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/

尝试:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM