1
<button ng-click="btn_save">Save</button>
<button ng-click="btn_update">update</button>

I want to cach and display alert for ng-click event of btn-save only anjular js.give me some best practice for done this job.

1 Answer 1

3

First you need to add an app and a controller where you will implement your logic.

The aplication logic goes in the controllers. Aviod putting it in the templates.

Example:

template

<div ng-app="myApp">
<div ng-controller="MyCtrl">
 <button ng-click="btn_save()">Save</button>
 <button ng-click="btn_update()">update</button>
</div>

controller

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
    $scope.btn_save = function(){
        alert("Button save clicked!")
    }
}

Is here, in the controller where you will implement the btn_save logic. In this case, the function throw an alert dialog when user clicks on button.

Here is the fiddle https://jsfiddle.net/xeq23e19/

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.