ng-repeat和保存功能不起作用

时间:2015-05-18 06:46:40

标签: javascript html angularjs ng-repeat

我的ng-repeat和save功能存在问题。第二次发布新主题时,第一个主题评论会自动重复。

  

块引用   Html文件

这是我的HTML文件:

我的ng-repeat和save功能存在一些问题。

<div ng-controller="TopicCtrl">
  <div class="container-fluid" style="margin:20px;padding-left:25px; ">
    <div class="row well">
      <div class="col-md-5">
        <form class="form-inline" role="form">
          <div class="col-md-12">
            <h4>Group Discussion Form</h4>
          </div>
          </br>
          <div class="form-group">
            <label for="Topic">Topic:
            </label>
            <input type="text" class="form-control" ng-model="discussion" ng-model-options="{ updateOn: 'blur' }">
            <button class="btn btn-primary" ng-click="Post()">Post</button>
          </div>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel panel-default" style="margin:20px;padding-left:25px;">
      <div ng-repeat="i in list" class="ng-scope" limitTo:display_limit>
        <div class="panel-body">Topic {{ $index+1 }}
          <div class="panel-body">{{i.name}}</div>
        </div>
        <ul id="todo-list">
          <div ng-repeat="todo in todos | filter:search" limitTo:inner_display_limit>
            <pre>{{todo.name}}</pre>
          </div>
        </ul>
        <label for="Comment">Comment:</label>
        <textarea ng-model="newToDo.name" cols="25" rows="4"></textarea>
        <button class="btn btn-xs btn-success" type="submit" ng-click="saveTodo(todo)">Save</button>
      </div>
    </div>
  </div>
  </form>
</div>

以上代码是我的Html文件......

Js档案:

angular.module('masters').controller('TopicCtrl', function ($scope, $rootScope) {

     $scope.list = [];

     $scope.Post = function () {
         $scope.list.push({
             name: $scope.discussion,

         });

         $scope.discussion = " ";
         console.log($scope.list);
     };

   $scope.todos = [];
     $scope.newToDo = {};


     $scope.saveTodo = function (todo) {

         $scope.currentItem = $scope.newToDo;
         $scope.todos[$scope.currentItemIndex] = $scope.newToDo;
         $scope.todos.push($scope.newToDo);
         $scope.newToDo = "";

     };


 });

以上代码是我的JS文件

0 个答案:

没有答案