gpt4 book ai didi

javascript - angularjs ng-table/ng-repeat 行未加载

转载 作者:行者123 更新时间:2023-12-03 04:57:14 26 4
gpt4 key购买 nike

我正在尝试按照教程 Here 进行操作关于使用 ng-Table。如果我从 Git 下载整个示例,那么它加载得很好,但尝试自己遵循最简单的示例,那么列标题和过滤器会加载,但没有行?如果我在 HTML 中手动添加另一行,它确实会出现,因此问题似乎与数据绑定(bind)或 ng-repeat 有关。控制台中没有显示任何错误。

enter image description here

示例代码:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-resource.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-route.js"></script>
<link rel="stylesheet" ; href="https://unpkg.com/ng-table@4.0.0/bundles/ng-table.css">
<script src="https://unpkg.com/ng-table@4.0.0/bundles/ng-table.js"></script>
</head>
<body>

<div ng-app="MyApp" ng-controller="MyCtrl">

<table ng-table="vm.tableParams" class="table" show-filter="true">
<tr ng-repeat="user in $data">
<td title="'Name'" filter="{ name: 'text'}" sortable="'name'">
{{user.name}}
</td>
<td title="'Age'" filter="{ age: 'number'}" sortable="'age'">
{{user.age}}
</td>
</tr>
</table>
</div>


<script>
var app = angular.module("MyApp", ["ngTable"]);

app.controller('MyCtrl', function ($scope, NgTableParams) {
var self = this;
var data = [{ name: "Moroni", age: 50 } /*,*/];
self.tableParams = new NgTableParams({}, { dataset: data });
});

</script>
</body>
</html>

最佳答案

您尚未指定 Controller 引用。

将代码更改为 <div ng-app="MyApp" ng-controller="MyCtrl as vm">它会按照您的预期工作。

工作示例:http://codepen.io/DeividasK/pen/qrWqey?editors=1010

关于javascript - angularjs ng-table/ng-repeat 行未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42390002/

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