1

I am trying to pass an angular variable into a function click call. this is what im trying to do so far:

<button onclick="dialogBox(id)">Cancel</button>     

    $scope.dialogBox = function (id) {
     console.log('Succesfully submitted id: '+id);
    });
2
  • 4
    ng-click="expression" Commented Nov 30, 2014 at 0:46
  • 2
    @Dylan is spot on about ng-click instead of onclick. Make sure that the dialogBox function is available to the scope that the button is on (typically inside a controller or directive). Also, what's the id variable? with the given code, id isn't defined. Commented Nov 30, 2014 at 0:47

2 Answers 2

2

onclick is a normal JavaScript event binder instead of an Angular one. You need to use global variables/functions in the onclick expression. However, in your code, dialogBox() is a function of $scope. So, if your button tag is wrapped inside the corresponding controller, just use ng-click instead. Like:

<button ng-click="dialogBox(id)">Cancel</button>     
Sign up to request clarification or add additional context in comments.

2 Comments

As a reminder, if you found this answer useful (and you should, since it is the correct answer), you should select it as the answer.
Thanks. that was the issue.
0

ng-click is the to slove this problem

<button ng-click="dialogBox(id)">Cancel</button> 

Comments

Your Answer

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