Al.s
Al.s

Reputation: 310

javascript function wont recognize angular variable passed to it

I'm trying to pass 3 arguments im gettting using ng-repeat to javascript function but i cant figure out how. i tried to do it this way:

  <tbody ng-repeat="(user_id, row) in data">
                <tr ng-repeat="(script_id, cron_format) in row ">
                    <td ng-model="user_name">{{user(user_id)}}</td>
                    <td ng-model="script_name">{{script(script_id)}}</td>
                    <td ng-model="cron_format"><span ng-repeat="l in letters(cron_format) track by $index">{{l}}</span><button class="save"  onclick="saveCron(user_id,script_id,cron_format)">save</button></td>
                </tr>
            </tbody>

but it wont work can someone explain why please?

Upvotes: 1

Views: 41

Answers (2)

squiroid
squiroid

Reputation: 14027

You should use ng-click for angular click events so:-

   <td ng-model="cron_format"><span ng-repeat="l in letters(cron_format) track by $index">{{l}}</span><button class="save"  ng-click="saveCron(user_id,script_id,cron_format)">save</button></td>
                </tr>

will help you out.

Upvotes: 1

Wolfack
Wolfack

Reputation: 2769

The above code is not working because you are using the wrong syntax.

The function for javascript should not be called within the curly braces else it should be called directly. Like you have called another JS function in line 5 of your code as follows:

onclick = "anyFunction()"

Upvotes: 0

Related Questions