Angularjs 获取输入字段值的jQuery

Angularjs 获取输入字段值的jQuery,angularjs,Angularjs,目前我有这个jQuery $('body').on('click','.plot', function(){ var y = $('input[name="gps[]"]').map(function() {return this.value;}).get(); console.log(y); console.log(y[0]); }); 我试过以下方法 theApp.controller('MenuSideController'

目前我有这个jQuery

    $('body').on('click','.plot', function(){
        var y = $('input[name="gps[]"]').map(function() {return this.value;}).get();
        console.log(y);
        console.log(y[0]);
    });
我试过以下方法

theApp.controller('MenuSideController', ['$scope', function($scope) {
    $scope.addnewmarker = function() {
        var newdiv = document.createElement('div');
        newdiv.innerHTML = "<input type='text' name='gps[]' placeholder='Enter Address or Lat/Lon'>";
        document.getElementById('marker').appendChild(newdiv);
        counter++;
    };
    $scope.plotmarkers = function() {
        var y = document.getElementsByName('gps[]').map(function() {
            return this.value; 
            }).get();
        }
        console.log(y);
    };
}]);
app.controller('menusiedcontroller',['$scope',函数($scope){
$scope.addnewmarker=函数(){
var newdiv=document.createElement('div');
newdiv.innerHTML=“”;
document.getElementById('marker').appendChild(newdiv);
计数器++;
};
$scope.plotmarkers=函数(){
var y=document.getElementsByName('gps[]).map(函数(){
返回此.value;
}).get();
}
控制台日志(y);
};
}]);
html

    <div id="marker">
        <input type="text" name="gps[]" id="gps">
        <input type="text" name="gps[]">
    </div>                          
<input type="button" value="Add another marker input" ng-click="addnewmarker();"></br>

<button class="plot btn" ng-click="plotmarkers()">Plot</button>


情节
我正在尝试使用
ng click
将一个小流程改为角度工作,但我似乎无法使其工作,有人能帮我吗


注意:输入是动态添加的,所以我永远不知道会有多少输入,我尝试用Angular而不是jQuery来做这件事。在jQuery中,您设计一个页面,然后使其成为动态页面。这意味着您可以使用jQuery直接修改DOM。但在angular js中,创建修改DOM的自定义指令

为了动态添加文本字段,我创建了一个控制器,如下所示

app.controller('MainCtrl', function($scope) {
  $scope.inputFields = [];
  $scope.count = 0;
  $scope.addField = function(){
    $scope.inputFields.push({name:"inputText"+$scope.count++});
  }
});
有一个名为addField()的函数。在div或按钮等元素的单击事件上调用此函数。检查以下html代码

<div ng-click="addField()">Click here to add</div>
<div ng-repeat="inputField in inputFields">
   <input type="text" name="inputField.name">
</div>
单击此处添加
您必须阅读本文: . 查看以下链接,了解如何添加表单字段


  • 我明白你在说什么,但我只是想从输入中提取数据,如果可能的话?