所以我有以下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不起作用。
知道为什么吗?
ž
答案 0 :(得分:2)
我可以发现两件事:
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>
解决这两个问题,看看是否能解决问题。