ng-repeat无法正常工作。认为存在范围问题,但不确定。

赞德法克斯

所以我有以下div:

<div id="chatrooms" ng-controller="TableMsgController">
<section id="chatroom">
<div id="messages"  >
    <ul>
      <li ng-repeat="entry in seenMsgs">{{entry.msg}}</li>
    </ul>
 </div>
 <form action="">
     <input type="text" id="userMsg" ng-model="userMsg">
    <input type="button" class="gButton" id= "sendMsgBtn" value="Send" ng-click="sendMsg()" />

    </form>
  </section>
</div>

我有以下控制器:

tables.controller('TableMsgController',function ($rootScope,$scope) {
  $scope.msgSeen = [];
  $scope.sendMsg = function () {
    //console.log("sendMsg button pushed");
    //console.log($scope.userMsg);
    $scope.msgSeen.push( {'msg':$scope.userMsg} );
   // console.log($scope.msgSeen);
};

ng-repeat无法正常工作。

知道为什么吗?

戴夫·本森·菲利普斯(DaveBensonPhillips)

我可以发现两件事:

a)您缺少以下内容的结尾括号sendMsg

tables.controller('TableMsgController',function ($rootScope,$scope) {
  $scope.msgSeen = [];
  $scope.sendMsg = function () {
    //console.log("sendMsg button pushed");
    //console.log($scope.userMsg);
    $scope.msgSeen.push( {'msg':$scope.userMsg} );
   // console.log($scope.msgSeen);
  }    <---------------------------------------------- :)
};

和b)您msgSeen在范围内定义,但正尝试迭代seenMsgs

<li ng-repeat="entry in seenMsgs">{{entry.msg}}</li>

解决这两个问题,看看是否可以解决。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章