0

I have this jQuery function:

   function updateProfile(profile, sessionId){
    alert(profile,sessionId);
}

In HTML I have like this

<button onclick="updateProfile(profile, {{sessionId}})">Update</button>

It doesn't work since the {{sessionId}} is the angularjs variable.

What is the correct way to pass this angularjs variable inside the jquery onclick function?

Thank you all for participating!

3
  • Possible duplicate of how to pass angular js variable inside onclick function as parameter
    – 4b0
    Commented Mar 2, 2018 at 11:29
  • I saw that answer, but mine is a bit different because I must use the onclick for a jquery function and the ng-click for angularfunction ONCLICK is for updates on the table (but does not send update on servers) NG-CLICK has some other params that sends to the server
    – DuliNini
    Commented Mar 2, 2018 at 11:31
  • @DuliNini you should avoid using jQuery in the first place. It is used for DOM manipulations which angularjs does with directives (that use jQLite) Commented Mar 2, 2018 at 11:43

1 Answer 1

0

Use ng-click instead of onclick and define your function in your scope

//HTML
<button ng-click="updateProfile(profile, {{sessionId}})">Update</button>

//Angular
$scope.updateProfile = function(profile, sessionId){
    alert(profile,sessionId);
}
1
  • Not what I mean exactly. Well I want to have onclick instead of ng-click So this is a jquery function not an angular function
    – DuliNini
    Commented Mar 2, 2018 at 14:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.