0
我試圖在角1AngularJS 1 - NG-不重複陣推後重新渲染
控制器代碼simpliest聊天應用:
app.controller('mainCtrl', function ($scope, $rootScope, $routeParams, $location, $http) {
$scope.messages=[{'name':'user','text':'test'}];
$scope.submitMessage = function() {
$scope.messages.push({'name':'newuser','text':$scope.mymessage});
}
});
模板:
<div class="page-content" ng-controller="mainCtrl" ng-init="init()">
<div class="messages">
<p class="chat-message" ng-repeat="message in messages"><span class="username">{{message.name}}: </span>{{message.text}}</p>
</div>
<div style="clear:both"></div>
<form ng-submit="submitMessage()" ng-controller="mainCtrl">
<input type="text" ng-model="mymessage" class="message-input" ></input>
</form>
當試圖console.log $ scope.messages數組時,它顯示新的值,但列表本身根本不會改變。可能是什麼原因?