Angularjs 无法使用ng repeat将数据加载到表中
代码: 检查DOM只显示表头和注释掉的Angularjs 无法使用ng repeat将数据加载到表中,angularjs,Angularjs,代码: 检查DOM只显示表头和注释掉的 我猜angular js与jquery函数冲突 angular core之外任何更改范围的事件都需要通知angular运行摘要循环以更新视图 由于您没有使用angular$http发出ajax请求,因此需要在成功回调中执行此操作 Uncaught TypeError: $http is not a function(anonymous function) @ (index):197jQuery.event.dispatch @ joint.js:4683
我猜angular js与jquery函数冲突 angular core之外任何更改范围的事件都需要通知angular运行摘要循环以更新视图 由于您没有使用angular
$http
发出ajax请求,因此需要在成功回调中执行此操作
Uncaught TypeError: $http is not a function(anonymous function)
@ (index):197jQuery.event.dispatch
@ joint.js:4683jQuery.event.add.elemData.handle
@ joint.js:4367
$http
不是函数的错误意味着您没有将$http
注入控制器您的问题是您试图混合使用jQuery和Angular。这是不安全的,任何人都不推荐
Angular无法知道jQuery正在工作,因为您使用了jQuery侦听器(带有$('#get')。请单击(…)
)。如果你想用角度,就用它。使用ng click
指令并使用$http
服务
success: function (data){
$scope.rowCollection = data[0];
$scope.$apply();
console.log("Result from Database: ", data[0]);
console.log("typeOf json is: " + jQuery.type(data));
}
var-app=angular.module('myApp',['smart-table']);
app.controller('MyController',函数($scope,$http){
$scope.get=function(){
$http.get('JsonProcessor.do').success(函数(数据){
$scope.rowCollection=数据[0];
log(“来自数据库的结果:,数据[0]);
log(“json的类型是:”+jQuery.type(数据));
});
$(“#对话框”).show();
});
});
得到
唯一Id
创建日期
文档Url
时间戳
{{row.ID}}
{{row.DATE_CREATED}}
{{row.URL}}
{{row.TIMESTAMP}
显示jQuery代码,但不说明问题所在。然后你告诉我角度代码有什么问题,但不显示代码。很难提供帮助。$http
错误是因为您忘记注入$http
以使其可用。使用$。ajax
在angular之外,需要使用$通知angular范围的更改。apply
@jbnize无需显示。这就是我所有的代码。@charlietfl我尝试将$http
作为函数($scope,$http)
注入,但它不起作用,所以我使用$.ajax
来获取数据。我不明白你所说的用$通知是什么意思。应用?你说:我用$http试过了。我没有看到任何使用$http发布的代码行。那么,你试过了吗?如果有,代码在哪里?我可以在console.log()中看到数据
但表格是这样打印的:
所以实际上创建了四行,但没有显示数据Hanks但我只是按照@Magus的建议将代码更改为angular,但有一个问题是表格行被创建了,但像这样是空的:
视图中使用的数据的属性必须是不正确的视图代码显示的如果可以,请在后端的视图{{rowCollection | json}
中打印集合,我正在使用带有键值对的Hasp映射。是否有一种方法可以在angular中检索键值。我很困惑,因为console.log(数据[0].ID)代码>正在打印我对此感到困惑的值。复制数据样本并创建演示,在类似plunker的沙箱中复制问题
var app = angular.module('myApp', ['smart-table']);
app.controller('MyController', function ($scope, $http) {
$scope.get = function() {
$http.get('JsonProcessor.do').success(function(data) {
$scope.rowCollection = data[0];
console.log("Result from Database: ", data[0]);
console.log("typeOf json is: " + jQuery.type(data));
});
$('#dialog').show();
});
});
<div id="get" ng-click="get()">GET</div>
<div id="dialog" class="bs-example web_dialog">
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th>Unique Id</th>
<th>Date Created</th>
<th>Doc Url</th>
<th>Time Stamp</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td>{{row.ID}}</td>
<td>{{row.DATE_CREATED}}</td>
<td>{{row.URL}}</td>
<td>{{row.TIMESTAMP}}</td>
</tr>
</tbody>
</table>
</div>
var app = angular.module('myApp', ['smart-table']);
app.controller('MyController', function ($scope, $http) {
$scope.get = function() {
$http.get('JsonProcessor.do').success(function(data) {
$scope.rowCollection = data[0];
console.log("Result from Database: ", data[0]);
console.log("typeOf json is: " + jQuery.type(data));
});
$('#dialog').show();
});
});
<div id="get" ng-click="get()">GET</div>
<div id="dialog" class="bs-example web_dialog">
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th>Unique Id</th>
<th>Date Created</th>
<th>Doc Url</th>
<th>Time Stamp</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td>{{row.ID}}</td>
<td>{{row.DATE_CREATED}}</td>
<td>{{row.URL}}</td>
<td>{{row.TIMESTAMP}}</td>
</tr>
</tbody>
</table>
</div>