gpt4 book ai didi

javascript - 我的 Angular View 未随数据表单服务器更新

转载 作者:行者123 更新时间:2023-11-28 19:36:49 25 4
gpt4 key购买 nike

我正在使用 Angularjs,并调用表单服务器来检索数据。数据已成功检索,但我的 View 未更新。我不明白为什么。这是我使用的代码。

Angularjs 和 html 代码:

<div class="row custom-margin" ng-controller="ListCtlr" ng-init="initData()">
<form class="form-inline" role="form" id="formId" name="formId">
<div class="form-group">
<label for="searchInput">Data to search</label>
<input ng-model="searchInput" placeholder="Enter term to search">
</div>
<button type="submitSearch" class="btn btn-primary" ng-click="search()">Go</button>
</form>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr class="info">
<th colspan="4" class="centertext">Name</th>
<th colspan="3" class="centertext">Age</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in persons">
<td>{{person.name}}</td>
<td>{{person.age}}</td>
</tr>
</tbody>
</table>
</div>
</div>

Controller 代码:

function ListCtlr($scope, $http, $location,$filter) {

$scope.formId = {searchInput: ''};

$scope.search = function () {
var url='server/search/'+this.searchInput;

$http.get(url)
.success(function (data) {
$scope.persons = data;

})
.error(function(data){
$scope.error = data;
});

};

}

当我检查从服务器检索的数据时,我得到以下 JSON 数据:

[{"name":"John","age":12},{"name":"Mary","age":25},{"name":"Garry","age":28}]

请问还缺少什么?

最佳答案

改变

    <tr ng:repeat="person in persons">
<td>{{person.name}}</td>
<td>{{person.age}}</td>
</tr>

    <tr ng-repeat="person in persons">
<td>{{person.name}}</td>
<td>{{person.age}}</td>
</tr>

关于javascript - 我的 Angular View 未随数据表单服务器更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25739790/

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