0

I'm Working in a personal project but I have a small problem when i want to render some data binding from angularjs in jquery, this is the code.

<div class="claimButton claimActive">
    <a href="{{ product.url }}" target="_blank" onclick="startTimer({{ $index }},{{ product.time }})">CLAIM</a>
</div>

The principal problem inside here

This the original code onclick="startTimer(0,5)" but when i turn in databinding from angularjs onclick="startTimer({{ $index }},{{ product.time }})" stop working and no render the numbers.

I hope that somebody help me to resolve this problem.

Johan
  • 159
  • 1
  • 9
  • 5
    Your question is not very clear, you need to show more code, and describe exactly what issue you are having – Jamiec Jun 09 '16 at 09:10
  • Possible duplicate of [jQuery click bind with angularjs](http://stackoverflow.com/questions/16097374/jquery-click-bind-with-angularjs) – Ken Y-N Jun 09 '16 at 09:11
  • ngclick is no working – Johan Jun 09 '16 at 09:12
  • use ng-click directive – etee Jun 09 '16 at 09:14
  • when I try to use ng directive then all the onclick is null – Johan Jun 09 '16 at 09:16
  • try that onclick="angular.element(this).scope().(this)" - if i understand your question well – Erez Jun 09 '16 at 09:28
  • My problem is: This the original code `onclick="startTimer(0,5)"` but when i turn in databinding from angularjs `onclick="startTimer({{ $index }},{{ product.time }})"` , stop working and no render the numbers. – Johan Jun 09 '16 at 09:34
  • Excuse me for no explain good, English is me second language. – Johan Jun 09 '16 at 09:35

1 Answers1

0

Assuming you have angular app and controller you can do so

<div class="claimButton claimActive">
    <a href="{{ product.url }}" target="_blank" ng-click="startTimer($index,product.time)">CLAIM</a>
</div>

and in the controller

$scope.startTimer = function(x,y){
    //do your code  x=$index, y=product.time
}
Erez
  • 574
  • 1
  • 6
  • 23
  • I Already made the changes, but still no working, it render when I use ng directive but is necessary the function onclick for start the timer when is clicked. – Johan Jun 09 '16 at 10:07
  • i guess i miss understood your question than! and i guess that you not staying in that page when you click the claim ? means that the controller binding again if you use the same controller – Erez Jun 09 '16 at 10:17
  • You can try the project here https://www.astrofeina.co/angularjs/ so when you click in CLAIM the counter start when the code is `onclick="startTimer(0,5)"` but when the code is `onclick="startTimer({{ $index }},{{ product.time }})"` the numbers no render please check and tell me if you see something – Johan Jun 09 '16 at 10:27
  • so that didnt help? onclick="angular.element(this).scope().startTimer(this)" but cant pass params – Erez Jun 09 '16 at 10:32
  • this is a ticking clock check it please – Erez Jun 09 '16 at 11:13
  • chek it https://plnkr.co/edit/m1R1PesR0HoblSaN6M1T?p=preview this, so now try to `onclick="startTimer({{ $index }},{{ product.time }})"` to `onclick="startTimer(0,5)"` and you gonna see how its work – Johan Jun 09 '16 at 11:26
  • the script is working good but now i need to render the numbers in binding but is no render the numbers, good idea use the plnkr – Johan Jun 09 '16 at 11:29
  • I already check, so ¿Do you think that probably I have to turn my jQuery script to AngularJS?, is not way to render the binding x,y in `onclick="startTimer(x,y)"`? – Johan Jun 09 '16 at 12:19
  • yah or you can do it with out passing params like this one i showed you with onclick - updated plnkr check the second claim btn – Erez Jun 09 '16 at 12:21
  • ¿can you implement `onclick="angular.element(this).scope().startTimer(this)"` in my Plunker? maybe im not doing this good as well – Johan Jun 09 '16 at 12:24
  • updated my plnkr the way you want. ofcurse you need to updrade that to work the way you want but its in general – Erez Jun 09 '16 at 12:30
  • ¡Thank You for your help! now I have idea about what to do – Johan Jun 09 '16 at 12:36