javascript函数无法识别传递给它的角度变量

javascript function wont recognize angular variable passed to it

本文关键字:变量 函数 识别 javascript      更新时间:2023-09-26

我试图通过ng repeat向javascript函数传递3个参数,但我不知道如何传递。我试着这样做:

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

但它不起作用,有人能解释一下为什么吗?

您应该使用ng-click来处理角度点击事件,因此:-

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

会帮你的。

上面的代码不起作用,因为您使用了错误的语法。

javascript的函数不应该在大括号内调用,否则应该直接调用。就像您在代码的第5行中调用了另一个JS函数一样,如下所示:

onclick = "anyFunction()"