angularjs(1.2.0)不能将结果打印到页面

时间:2013-11-14 15:11:50

标签: json angularjs

我有一个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)查看数据,但无论出于何种原因,我无法在页面本身上打印它。我不确定它是否容易丢失,但第二组眼睛会非常感激。

感谢

1 个答案:

答案 0 :(得分:0)

感谢您的评论,我能够缩小我的问题范围。我可能应该提到应用服务器是nodejs with expressjs使用hogan作为模板引擎...并猜测,hogan使用与angular相同的语法处理变量:\一旦我切换到ejs我能够打印到页面。

谢谢!