2

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?

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

1

You could try this - initialize a new model str_param using ng-init

<span ng-init="str_param = (wos.wordFormNgForm_{{wf.wordFormIdentity}} | toString)" 
ng-click="wos.wordFormDeleteDefinition(str_param, wf.wordFormId, d.wordDefinitionId)">
</span>

PS: I am not sure what these values are, if the above code fails, try removing the {{}} and | toString to see if that works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.