从datalist中选择一个选项后调用一个函数

时间:2018-01-31 08:39:59

标签: html angularjs



select * from cijfer where naam=naam

select * from cijfer where naam=:naam




嗨,这是我的代码的一部分我试图调用一个函数并传递所选选项(记录)的id,但它没有调用该函数。我也尝试过ng-click。我错过了什么?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您需要 <select> 而不是数据列表,还要使用 ng-model 变量

<强> DEMO

var app = angular.module('testApp',[]);

app.controller('testCtrl',function($scope){

$scope.empobj=[{first_name:"new",last_name:"sjkk",id:"2"},{first_name:"new",last_name:"sjkk",id:"3"},{first_name:"new",last_name:"sjkk",id:"4"}];

$scope.selectedemp1= function(id){
console.log(id);
}

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<input type="text" class="form-control" id="inputemployee" ng-model="empname" list="suggestions"   > 
                    
<select ng-options="emp as  emp.last_name for  emp in empobj" 
   ng-model="selected" ng-change="selectedemp1(selected.id)"></select>
   
 </body>