gpt4 book ai didi

javascript - 从 Controller 函数调用 ng-repeat

转载 作者:行者123 更新时间:2023-12-03 11:51:14 27 4
gpt4 key购买 nike

我想使用 ng-repeat 写出我的应用程序中某些项目的列表,但我遇到了这个问题:

模板

<ion-slide-box  on-slide-changed="slideHasChanged($index)" ng-controller="AccountCtrl" ng-init="getData()">
<ion-slide ng-repeat="statitem in stats">
<div class="box vh80">
<h1>{{statitem.name}}</h1>
<h1>Test</h1>
</div>
</ion-slide>
</ion-slide-box>

并在AccountCtrl

angular.module('starter.controllers', [])
.controller('AccountCtrl', function($scope, Friends) {

$scope.getData = function() {

console.log('test');
var friends = [
{ id: 0, name: 'Scruff McGruff' },
{ id: 1, name: 'G.I. Joe' },
{ id: 2, name: 'Miss Frizzle' },
{ id: 3, name: 'Ash efe' }
];
$scope.stats = friends;
}
});

问题是,模板中没有获取任何项目。

请问哪里有问题?

感谢您的帮助。

编辑:

我通过将方法调用移动到父 div 来解决这个问题。

<ion-content class="padding" ng-controller="AccountCtrl" ng-init="getData()">

最佳答案

尝试稍微清理一下模板以进行测试,以确保您的 HTML 100% 正确,因此您可以这样做:

<div ng-controller="AccountCtrl" ng-init="getData()">
<div ng-repeat="statitem in stats">
<h1>{{statitem.name}}</h1>
</div>
</div>

如果您看到任何结果,那么您必须检查您的 HTML 和 CSS 模板。

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

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