2016-07-11 5 views
-1

こんにちは(それがangurla-ツールチッププラグインのattributです)私のhtmlタグの1の値を持つtooltip attributに従って持っている:attribut値の文字列を作る

<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> 

を私が作ることができますどのように私のjavascriptの変数にtooltip属性内の属性値から代入しますか?私は次のように試しました:

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;}"; 

どちらもうまくいきません。

アイデア?

EDIT(SOLUTION):How can I build a json string in javascript/jquery? - それはJSON.stringify()

おかげ

+0

これで、データの束を変数に格納し、それを 'tooltip'属性に入れようとしていますか? –

+0

これを試してみてくださいmyAttributValue = JSON.parse(myAttributValue) –

+0

@Rakesh Kumarは自分で試してみてください。うまくいきません。 –

答えて

1

で動作するには、角度結合は、例えば、二重括弧の構文を使用します。

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

あなたのJavaScriptで、あなたが希望を持っている:

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

EDIT:

ツールチップの内容は、JSONのような文字列内にある場合、あなたが行うことができます:

var l_tempo = JSON.parse(<your string>) ; 
$scope.Thisisthetooltip = l_tempo.<the path to the element within the JSON> ; 

これはまだあなたの質問に答えていない場合は、あなたがダウン投票を残すことができます。

+0

これは私の問題を解決するものではありません。私は上記の文字列をjavascriptの変数に代入する方法を知らない。これは本当に私を助けるものではありません... – MrBuggy

+0

"代入"という意味が明確ではありません。課題はどこで行われますか? – FDavidov

+0

私の質問をもう一度見てみると、最初のコードでは、属性ツールチップを使ってdivを見ることができます。この属性には値があります。今度は2番目のコードを見ると、属性の値をコピーして文字列を作り、それを変数に入れたいと思います。変数myAttributeValueのようにしようとしましたが、間違っています。正しいものではありませんstring ... – MrBuggy

関連する問題