-1

Hi I've got follow tooltip attribut with a value in one of my html tags (it's an attribut for a angurla-tooltip plugin):

<div tooltip="{ data: { onChange: ctrl.onChangeInTooltip }, template: '<wsc-number-input-helper-tooltip on-change=&quot;ctrl.data.onChange&quot;></wsc-number-input-helper-tooltip>', class: 'cNumberInputHelperTooltip', pointerPosition: 'End'}"></div>

How can I make a string and assign it to a variable in my javascript from the attribut value within the tooltip attribut? I've tried it like this:

let myAttributValue = "{ data: { onChange: ctrl.onChangeInTooltip }, template: '<wsc-number-input-helper-tooltip on-change=&quot;ctrl.data.onChange&quot;></wsc-number-input-helper-tooltip>', class: 'cNumberInputHelperTooltip', pointerPosition: 'End'}";
let myAttributValue = "{ data: { onChange: ctrl.onChangeInTooltip }, template: &quot;<wsc-number-input-helper-tooltip on-change=&quot;ctrl.data.onChange&quot;></wsc-number-input-helper-tooltip>&quot;, class: &quot;cNumberInputHelperTooltip&quot;, pointerPosition: &quot;End&quot;}";

Both don't work.

Any ideas?

EDIT (SOLUTION): How can I build a json string in javascript/jquery? - it works with JSON.stringify()

Thanks

Community
  • 1
  • 1
webta.st.ic
  • 4,781
  • 6
  • 48
  • 98
  • So you are trying to store the bunch of data into the variable and put it in the `tooltip` attribute? –  Jul 11 '16 at 07:24
  • Try this myAttributValue = JSON.parse(myAttributValue) – Rakesh Kumar Jul 11 '16 at 07:25
  • @Rakesh Kumar try it yourself and you may find that it doesn't work –  Jul 11 '16 at 07:26
  • Yes something like this. Because, I've got an input with a button on the right side. The html of the button contains this tooltip attribut with it's value and calls the tooltip. But on tablet devices, the button is hidden and the tooltip should be opened with the click on the input, so I have to add the attribut and the value dynamicly to the input when it's a tablet device. When it's a desktop, the input has no click events for the tooltip. – webta.st.ic Jul 11 '16 at 07:27
  • Possible duplicate of [How can I build a json string in javascript/jquery?](http://stackoverflow.com/questions/10559660/how-can-i-build-a-json-string-in-javascript-jquery) – webta.st.ic Jul 11 '16 at 07:46

1 Answers1

1

Angular binding uses double-braces syntax, for instance:

<div tooltip="{{Thisisthetooltip}}" ... >

where in your JavaScript you would have:

$scope.Thisisthetooltip = "This is the actual tooltip text" ;

EDIT:

If the contents of the tooltip is within a JSON-like string, you can do:

var l_tempo = JSON.parse(<your string>) ;
$scope.Thisisthetooltip = l_tempo.<the path to the element within the JSON> ;
miken32
  • 42,008
  • 16
  • 111
  • 154
FDavidov
  • 3,505
  • 6
  • 23
  • 59
  • This doesn't really solve my problem. I don't know how to assign the above string to a variable in javascript. This doesn't really help me... – webta.st.ic Jul 11 '16 at 07:29
  • It is not clear what you mean by "assign". Where is the assignment taking place? – FDavidov Jul 11 '16 at 07:30
  • When you look again on my question, in the first code, you can see a div with a attribut tooltip. This attribut has a value. Now when you look on the second code, I would like to copy out the value of the attribut and make a string of it and put it in a variable.. I tried it like in the variable myAttributeValue but it's wrong, it's not a correct string... – webta.st.ic Jul 11 '16 at 07:33
  • Your whole string looks like a stringified JSON. Parse it and then try again. – FDavidov Jul 11 '16 at 07:35
  • Check the EDIT of my previous answer. – FDavidov Jul 11 '16 at 07:36
  • Hi I'm trying it, it's sure the right way with JSON.parse() but I can't really get it without errors. Can you perhaps make a edit with my example within? So I can see how I have to do this exactly with the json above in my question? Thanks – webta.st.ic Jul 11 '16 at 07:40
  • I've got it: http://stackoverflow.com/questions/10559660/how-can-i-build-a-json-string-in-javascript-jquery - with JSON.stringify() it works for me, thanks! – webta.st.ic Jul 11 '16 at 07:42