gpt4 book ai didi

javascript - Angularjs ng-click 重复表行不起作用

转载 作者:IT王子 更新时间:2023-10-29 03:10:56 26 4
gpt4 key购买 nike

在 AngularJS 中 ng-click 以下 HTML 对我不起作用

<tr ng-repeat="ai in alert_instances" ng-click="go('/alert_instance/{{ai.alert_instancne_id}}')">
<td>{{ai.name}}</td>
<td>{{ai.desc}}</td>
</tr>

目前我的 Controller 中的“go”功能只有

$scope.go = function (hash) {
console.log("hi")
};

最佳答案

你做错了。您不应该在 Angular 指令 (ng-click) 中使用花括号,因为此语法是针对模板的。

正确的做法:

<tr ng-repeat="ai in alert_instances" ng-click="go(ai)">
<td>{{ai.name}}</td>
<td>{{ai.desc}}</td>
</tr>

$scope.go = function(ai) {
var hash = '/alert_instance/' + ai.alert_instancne_id;
//...
};

关于javascript - Angularjs ng-click 重复表行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15288047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com