如何以角度检索对象详细信息?

时间:2017-02-04 17:42:52

标签: javascript angularjs http firebase ionic-framework

我试图搜索我的问题的解决方案,但似乎我的代码应该工作。我已从firebase检索数据,并希望在我的视图中显示它。 当我在相关视图中时,数据对象在开发者控制台中显示为存在。

我的观点:

  <ion-view cache-view="false" ng-controller="PostCtrl">
   <ion-nav-title>{{ viewname }}</ion-nav-title>
     <ion-content class="has-header contentpane">

        <div class="titlepane">
            <h4 class="posttitle">
                {{item.title}}
            </h4>
            <p class="categorytitle">
                {{item.category}}
            </p>
        </div>

  </ion-content>
 </ion-view>

控制器:

firebaseApp.controller('PostCtrl', function ($scope, firebaseApi, $stateParams) {
'use strict';

// Create a name for the view to show as the title
$scope.viewname = 'Svampe';

// The stateParams is defined in the Services.js and defined in the scope here.
$scope.id = $stateParams.id;

// API call to the firebase for a specific post
firebaseApi.getSingle($scope.id).then(function (succ) {
  $scope.item = succ;
  console.log("Items", $scope.item);
}, function(err) {
  console.log('Error: ', err);
});

});

您是否知道数据未在视图中显示的原因?我可以看到该对象已成功检索但未显示。

1 个答案:

答案 0 :(得分:2)

试试这个

{{item.data.title}}

{{item.data.category}}

<强>小提琴:

http://jsfiddle.net/B9RsQ/40/