gpt4 book ai didi

javascript - ng-repeat中对象的AngularJS调用函数

转载 作者:行者123 更新时间:2023-11-29 16:54:55 25 4
gpt4 key购买 nike

我有以下 Controller :

app.controller('TestController', function($scope) {
$scope.tests = [{
name: 'Name 1',
description: 'Some Description',
actionHandler: function() {
alert('Action Handler called');
}
},
...
];
});

在我的文件我做一个 ng-repeat 像这样:

<div ng-repeat="test in tests">
<p>{{test.name}}</p>
<p>{{test.description}}</p>
<a ng-click="{{test.actionHandler}}">Click me</a>
</div>

它并没有真正起作用。我也试过了。

<a ng-click="test.actionHandler">Click me</a>

 <a ng-click="test.actionHandler()">Click me</a>

但似乎都不起作用。知道如何在 ng-repeat 中调用对象的函数吗?

谢谢,xCoder。

最佳答案

您的第三次尝试是 test.actionHandler() 的正确形式。也许您可以尝试在 Controller 'TestContorller', function($scope, $window) 中包括 $window 和 $scope 并将警报调用更改为 $window.alert('action handler称为') ...

关于javascript - ng-repeat中对象的AngularJS调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32995153/

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