2015-01-22 4 views
0

Ниже мой код angularjs: я не могу очистить inputComment поле после формы submit.AngularJs: Не удалось очистить поле ввода после формы sumbit

Здесь я могу добавить запись успешно, но после добавления записи я пытаюсь очистить поле ввода, но я не могу это сделать.

HTML code: 
<body ng-app="taskDemo" ng-controller="taskController"> 
    <div class="widget-body"> 
     <form class="add-task" ng-if="addNewClicked" ng-init="addNewClicked=false;"> 
     <div class=""> 
      <div class="input-group"> 
       <input name="comment" ng-model="inputComment" type="text" class="form-control" > 
        <div class="input-group-btn"> 
         <button ng-click="addTask(inputComment)" type="submit" class="btn btn-default"> 
          <i class="glyphicon glyphicon-plus"></i>&nbsp;Add New Task 
         </button> 
        </div> 
      </div> 
     </div> 
     </form> 
    </div> 
</body> 

JS Code: 
<script type="text/javascript" src="js/angular.min.js"></script> 
<script type="text/javascript" > 
     app = angular.module('taskDemo', []); 
     app.controller('taskController', function($scope, $http){ 
       $scope.addTask = function (task) { 
       $http.post("ajax/addTask.php?task="+task) 
        .success(function ($response) { 
         getTaskList();     
        }); 
       $scope.inputComment = ''; 

      }; 
     } 
    </script> 
+0

Что находится внутри 'getTaskList()' function? Убедитесь, что вы не определяете '$ scope.inputComment' внутри. – Kasyx

+0

Здесь getTaskList() Код: Функция getTaskList() { $ http.post ("Ajax/getTaskList.php") .success (функция ($ ответ) { $ scope.taskList = $ отклика; }); } – khanz

+0

@Kasyx: Не задавать $ scope.inputComment внутри getTaskList(), но я использую в нем модуль $ scope. – khanz

ответ

0

Читайте о Прототипическом Наследовании здесь: What are the nuances of scope prototypal/prototypical inheritance in AngularJS?

Изменить контроллер года к этому:

 app.controller('taskController', function($scope, $http){ 
      $scope.inputComment ={value:''}; 
      $scope.addTask = function (task) { 
      $http.post("ajax/addTask.php?task="+task) 
       .success(function ($response) { 
        getTaskList();     
       }); 
      $scope.inputComment ={value:''}; 

     }; 
    } 

и внутри YR изменений HTML страницы этого

<input name="comment" ng-model="inputComment" type="text" class="form-control" > 

в

<input name="comment" ng-model="inputComment.value" type="text" class="form-control" > 
+0

Было бы неплохо отметить, что на самом деле проблема и почему ваше решение может работать. – zeroflagL

Смежные вопросы