I want to empty the text box after the form is submitted in Angular

Asked 2 years ago, Updated 2 years ago, 60 views

It's just as the title says.In the Angular form, the controller wrote the process of emptying the text box when the value of the text box was sent, but I was struggling because it didn't work as well as I wanted in ng-repeat, so I asked you a question.

The assumption is that there are n items_list in one shop, and there are multiple items that are tied together.

shop(1)->item_list(n)->item(n)

The text box can be empty after submitting the form without any problems outside of ng-repeat (code for commenting out), but I am troubled that I cannot do the same in ng-repeat.Instead of emptying a specific text box, I just want to empty all the text boxes related to itemBody, but it doesn't work...Thank you for your cooperation.

angular.module('angularApp').controller "ShopController", ($scope)->
  $scope.addItem=(itemBody, contentId)->
    $scope.itemBody=""

-

.containerng-controller="ShopController"ng-init="init()"

  // form id="new_item"ng-submit="addItem(itemBody,item_list.id)"
    // input type="text" id="itemBody"ng-model="itemBody"
    // input type="submit" value="add"

  ul
    link-repeat = "item_list in article.item_lists"
      ul
        link-repeat = "item in item_list.items"
          input type="submit" value="delete"ng-click="deleteItem(item)"

        form id="new_item"ng-submit="addItem(itemBody,item_list.id)"
          input type="text" id="itemBody"ng-model="itemBody"
          input type="submit" value="add"

angularjs coffeescript

2022-09-30 15:36

1 Answers

ng-repeat generates a new scope, so I think it's not referenced.
First of all, I think the input field will be empty if you write it as below.
そのPlease note that we cannot guarantee the impact on other processes.

html Change the first argument of addItem to this

form id="new_item"ng-submit="addItem(this,item_list.id)"
  input type="text" id="itemBody"ng-model="itemBody"
  input type="submit" value="add"

js
Change the first argument of addItem to <object>
change itemBody to <object>.itemBody

angular.module('angularApp').controller "ShopController", ($scope)->
  $scope.addItem=(obj,contentId)->
    obj.itemBody=""


2022-09-30 15:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.