Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用angularjs删除输入字段的值_Angularjs_Symfony_Twig - Fatal编程技术网

如何使用angularjs删除输入字段的值

如何使用angularjs删除输入字段的值,angularjs,symfony,twig,Angularjs,Symfony,Twig,如果您这样做: var Note = function($scope){ $scope.items = []; $scope.add = function () { //angular way of implementing document.getElementByID(); pub1 = angular.element('#form_input_ppubs').val(); $s

如果您这样做:

 var Note = function($scope){
            $scope.items = [];

        $scope.add = function () {


          //angular way of implementing document.getElementByID();
          pub1 = angular.element('#form_input_ppubs').val();



          $scope.items.push({ 
            primaryPub: pub1

          });
        };
      }
您应该看到primaryPub的条目,它是您输入的模型。然后可以通过将模型置零来将其作为目标,因此:

console.log($scope.items);
但是,您在ng重复中使用此选项:

$scope.items.primaryPub = null;


因此,您的console.log(如果“items”中有多个项)应该为primaryPub显示类似数组的结构。

您不必像这样检索项目。这是丑陋的,不是棱角分明的方式<代码>angular.element('#form_input_ppubs').val()

相反,只需使用
ngModel
在输入中引用它即可

在您的范围内声明它

<div ng-repeat="(i, item) in items">
  <input type="text" placeholder="new input" ng-model="items[i].primaryPub">
</div>
HTML

$scope.inputItem = null;
使用ng单击调用它

$scope.addItem = function(item) {
    $scope.items.push(item);

    //reset the model
    $scope.inputItem = null;
}
添加项目

是一个演示,显示了使用ng模型清除输入字段。我无法创建ng模型属性,因为我正在使用Twig(Symfony)生成html页面@kkkkkkk
<input ng-model="inputItem " />
$scope.addItem = function(item) {
    $scope.items.push(item);

    //reset the model
    $scope.inputItem = null;
}
<button type="button" ng-click="addItem(inputItem)">Add Item</button>