gpt4 book ai didi

javascript - 完成时angularjs嵌套的ng-repeat函数调用

转载 作者:行者123 更新时间:2023-11-30 09:42:36 24 4
gpt4 key购买 nike

我有 2 个嵌套的 ng-repeat 和 bool 值,它们将隐藏加载 div,但加载 div 在所有内容呈现之前隐藏。 bool 值取决于获取所有数据的回调函数。

<tr ng-repeat="package in packages track by $index">
<td> {{ pack.Name }}</td>
<td>
<select ng-hide="package.spinStart" class="form-control" ng-model="package.selectedVersion">
<option ng-repeat="pack in package.allPackageVersions track by $index"
value="{{pack.Version}}"
ng-hide="pack.shouldHide"
ng-disabled="!expertModeOn && pack.shouldDissable"
ng-style="!expertModeOn && pack.shouldDissable && {'color':'#ddd'}">

{{pack.NuGetPackageId}} | {{pack.Version}} | {{pack.Published}}
</option>
</select>

当所有 2 个嵌套循环都完成时,我如何调用该函数?

我尝试使用 $watch 语句和 指令。谢谢你!

最佳答案

你可以使用 $last 吗?

<!DOCTYPE html>
<html data-ng-app="myApp">

<head>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="script.js"></script>
</head>

<body data-ng-controller="testController">


<div ng-repeat="package in packages">
{{package.name}}
<div ng-repeat=" pkg in package.selectedVersion" ng-init="$last && call()">
{{pkg.name}}
</div>
</div>

<script>
angular
.module('myApp', [])
.run(function($rootScope) {
$rootScope.title = 'myTest Page';
})
.controller('testController', ['$scope',
function($scope) {
$scope.packages = [{
name: 'test1',
selectedVersion: [{
name: 'test_ver1'
}, {
name: 'test_ver2'
}, {
name: 'test_ver3'
}]
}, {
name: 'test2',
selectedVersion: [{
name: 'test_ver1'
}, {
name: 'test_ver2'
}, {
name: 'test_ver3'
}]
}];

var counter = 0
$scope.call = function() {
counter++
if (counter == $scope.packages.length) {
alert("All loops finished");
}
}
}
])
</script>
</body>

</html>

关于javascript - 完成时angularjs嵌套的ng-repeat函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40462852/

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