Javascript 在Angular JS中使用HTML select
我正在开发我的第一个角度应用程序。我的页面包含文本框和html选择元素。我使用Javascript 在Angular JS中使用HTML select,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,我正在开发我的第一个角度应用程序。我的页面包含文本框和html选择元素。我使用 <select data-ng-model="ddlLocation"> <option value="">--Select--</option> <option data-ng-repeat="location in vm.arrLocations" value="{{location.srNo}}">{{location.name}}<
<select data-ng-model="ddlLocation">
<option value="">--Select--</option>
<option data-ng-repeat="location in vm.arrLocations" value="{{location.srNo}}">{{location.name}}</option>
</select>
现在,如何在单击按钮时获取选定值。
在Angular JS中使用HTML select是否有其他CRUD功能方法?尝试以下方法:
this.getLocationsOnSuccess = function (response) {
//vm.locations = response.data;
var arrLocations = new Array();
var i;
for (i = 0; i < response.length; i++) {
vm.locationSrNo = response[i].srNo;
vm.locationName = response[i].name;
arrLocations.push({
srNo: response[i].srNo,
name: response[i].name
});
}
vm.arrLocations = arrLocations;
vm.whatIsMyValue = function() {
alert(vm.ddLocation);
}
}
this.getLocationsOnSuccess=函数(响应){
//vm.locations=response.data;
var arrLocations=新数组();
var i;
对于(i=0;i
在您的HTML中:
<button ng-click="whatIsMyValue()"></button>
它将显示您的值。正如您所看到的,您现在可以随心所欲地使用它 试试这个:
this.getLocationsOnSuccess = function (response) {
//vm.locations = response.data;
var arrLocations = new Array();
var i;
for (i = 0; i < response.length; i++) {
vm.locationSrNo = response[i].srNo;
vm.locationName = response[i].name;
arrLocations.push({
srNo: response[i].srNo,
name: response[i].name
});
}
vm.arrLocations = arrLocations;
vm.whatIsMyValue = function() {
alert(vm.ddLocation);
}
}
this.getLocationsOnSuccess=函数(响应){
//vm.locations=response.data;
var arrLocations=新数组();
var i;
对于(i=0;i
在您的HTML中:
<button ng-click="whatIsMyValue()"></button>
它将显示您的值。正如您所看到的,您现在可以随心所欲地使用它 您应该看看angularjs中哪一个功能很好。
在您的示例中实现这一点
<select ng-model="ddlLocation" ng-options="location as location.name for location in vm.arrLocations">
<option value="">--Select--</option>
</select>
您应该看看angularjs中哪一个功能很好。
在您的示例中实现这一点
<select ng-model="ddlLocation" ng-options="location as location.name for location in vm.arrLocations">
<option value="">--Select--</option>
</select>
您可以使用ng change函数并将您的模型传递给that,您可以使用ng change函数并将您的模型传递给that,我已经尝试在控制器上使用vm.ddlLocation,但它将始终返回默认选项,即--Select--“这是因为您需要将
vm.ddLocation
放入选择中,就像您对其他变量所做的那样。“您需要将vm.ddLocation放入您的选择中“表示编码时出现了愚蠢的错误。现在代码按预期工作。感谢您指出。我已经尝试在控制器上使用vm.ddLocation,但它始终会返回默认选项,即--Select--“这是因为您需要在Select中放入vm.ddLocation
,就像您对其他变量所做的那样。”您需要在Select中放入vm.ddLocation“意味着在编码时出现了愚蠢的错误。现在代码按预期工作。谢谢你指出。