ng重复工作但没有表现出表情

ng-repeat working but not showing expression

本文关键字:工作 ng      更新时间:2023-09-26

我对angular还很陌生,在表达式中显示范围变量时遇到了问题。它正确地重复项目,但不显示表达式。我尝试了绑定和其他选项,但没有成功。任何帮助都会很棒!感谢

//html     
<div >
      <div class="row pad" ng-repeat="boat in boats">
        <div class="col-xs-6 col-md-4"><img class="proimg" src="img/Example.png"></div>
          <div class="col-xs-12 col-md-8">
            <span class='text-center' >{{boat.title}}</span>
                <ul class="detailList">
                    <li>{{ boat.title }}</li>
                    <li ng-bind="description">{{ boat.description }}</li>
                    <li>{{ boat.price }}</li>    
          </div>
        </div>
    <hr>
 </div>
/js 
    var firebaseRef = new Firebase("https://mysite.firebaseio.com/boats");
    $scope.boats = firebaseRef

您以错误的方式使用firebase实现。您应该使用ref,它是firebasedb的根,使用适当的方法访问它的子级。由于firebase以异步方式工作,您可以传递回调并访问所需的数据,如所示

var firebaseRef = new Firebase("https://mysite.firebaseio.com/boats");
// Attach an asynchronous callback to read the data at our posts reference
firebaseRef.on("value", function(snapshot) {
  console.log(snapshot.val());
  $scope.boats = snapshot.val() 
}, function (errorObject) {
  console.log("The read failed: " + errorObject.code);
});

有关从firebase检索数据的详细信息,请参阅:https://www.firebase.com/docs/web/guide/retrieving-data.html.

建议使用Angular fire将firebase与angular一起使用,因为它通过angular服务提供了对firebase方法的良好包装。参考https://www.firebase.com/docs/web/libraries/angular/quickstart.html