0

I have this line to get a dom element. Actually it's in a angularjs component. I need to have the possibily to change following line.

$('[data-remodal-id=modal]').remodal(options);

to something like this :

var id = $ctrl.project.id;
$('[data-remodal-id=id]').remodal(options);

Problem is that i can't convert a string id to what i want or I'm not aware of this at moment. Hope you guys can help me.

As you guys can see this is uncommon jquery selector. I just tried this and it doesn't work.

$('[data-remodal-id="' + id + '"]') 

PS : using following jquery library : http://vodkabears.github.io/remodal/

  • Possible duplicate of [using variables within a jquery selector](http://stackoverflow.com/questions/4823339/using-variables-within-a-jquery-selector) – Heretic Monkey Dec 14 '16 at 16:23
  • @MikeMcCaughan Actually this answer is great but not enough couldn't solve my problem. – Joseph Gremaud Dec 15 '16 at 08:20
  • There's more than one answer on that question... It's not an uncommon selector at all. You need to show the HTML against which you're running this code, and more information than "it doesn't work". – Heretic Monkey Dec 16 '16 at 14:59

2 Answers2

2

You need string concatenation:

$('[data-remodal-id="' + id + '"]')
tymeJV
  • 103,943
  • 14
  • 161
  • 157
0

Just don't mix AngularJS and Jquery in components and directive it's a lot of trouble for nothing.

Finally i made my own modal box in angularJS.