我有一个 angularjs 视图,我正在尝试打印它的结果,即使索引和控制台输出显示了数据,我也无法让它显示在实际页面中。
我收到的 json 数据的控制台输出:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
0: Object
$$hashKey: "004"
_id: Object
$oid: "527994c48776385b2e4a6e78"
__proto__: Object
author: "Undefined author"
content: "Undefined content"
title: "stfu"
__proto__: Object
1: Object
$$hashKey: "005"
_id: Object
$oid: "52799b0a8776385c490cd268"
__proto__: Object
author: "adam-stokes"
content: "some content here"
title: "dieeeee"
我的控制器代码:
'use strict';
var cagewebControllers = angular.module('cagewebControllers', []);
cagewebControllers.controller('IndexCtrl', ['$scope', '$http',
function($scope, $http) {
$http.get('http://localhost:9000/entity/page').
success(function(data, status, headers, config) {
$scope.pages = data;
console.log($scope.pages);
});
}
]);
我的应用程序代码:
'use strict';
var cageweb = angular.module('cageweb', [
'ngRoute',
'cagewebControllers'
]);
cageweb.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
» when('/', {
» templateUrl: 'partials/index',
» controller: 'IndexCtrl'
» }).
» otherwise({
» redirectTo: '/'
» });
}]);
我的模板部分:
<h1>Pages</h1>
{{pages.length}}
<div ng-repeat="page in pages track by $id(page)">
page {{$$hashKey}} - {{page.title}}
</div>
我的模板布局:
<!DOCTYPE html>
<html ng-app="cageweb">
<head>
<title>{{ title }}</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<script src="javascripts/lib/jquery/jquery-1.10.2.min.js"></script>
<script src="javascripts/lib/angular/angular.js"></script>
<script src="javascripts/lib/angular/angular-animate.min.js"></script>
<script src="javascripts/lib/angular/angular-resource.min.js"></script>
<script src="javascripts/lib/angular/angular-route.min.js"></script>
<script src="javascripts/app.js"></script>
<script src="javascripts/controllers.js"></script>
</head>
<body>
<h1>cage-webbbbb</h1>
<div class="view-container">
<div ng-view class="view-frame"></div>
</div>
</body>
</html>
$scope.pages 确实包含 json 数据,我可以使用 console.log($scope.pages) 查看数据,但无论出于何种原因,我都无法将其打印在页面本身上。我不确定它是否容易丢失,但第二双眼睛将不胜感激。
谢谢