Alan Alan - 6 months ago 13
AngularJS Question

How can I pass a string in the click event with AngularJS?

How can I pass a calculated string to a function in AngularJS ?

Here's the code that I have:

<div ng-click="wos.wordFormRowClicked(wf)"
ng-form="wos.wordFormNgForm_{{wf.wordFormIdentity}}"
ng-repeat="wf in wos.word.wordForms">
<div>
<div ng-click="wos.wordFormDefinitionRowClicked(d)"
ng-repeat="d in wf.wordDefinitions">
<div>
<span ng-click="wos.wordFormDeleteDefinition("wos.wordFormNgForm_{{wf.wordFormIdentity}}", wf.wordFormId, d.wordDefinitionId)"
></span>
</div>


I'm trying to pass a string as the 1st parameter of the function
wos.wordFormDeleteDefinition
but it is giving me a run time error. How can I do this?

Answer

Since you want the string to be interpolated, pass the expression and the string as 2 differnt values to function and handle them in your controller:

<span ng-click="wos.wordFormDeleteDefinition('wos.wordFormNgForm_', wf.wordFormIdentity, wf.wordFormId, d.wordDefinitionId)"
                      ></span>