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 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 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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.