在Angular中选定的下拉菜单中,如何在按钮值中获得特定的ID? [英] How do I get particular ID in button value on selected dropdown in Angular?
问题描述
我正在使用一个表单,我想向特定用户发送电子邮件提交表单后.我可以得到一个下拉列表员工姓名.我将从列表中选择任何名称.在选择特定名称,他的电子邮件ID或ID应该放在电子邮件按钮的值中,以便点击电子邮件时,我将直接在电子邮件按钮上获得他的电子邮件ID.
I am working with a form where I want to send email to a particular user after form submission. There is one dropdown list where I can get employee names. I will select any name from the list. On select particular name, his email id or id should go into the value of the email button, so that on click email, I will get his email id directly on the email button.
我是Angular的新手.请帮忙.
I am new to Angular. Please help.
<select ng-model="empInfo1" ng-options="emp.candidate_name for emp in names4" class="span2"></select>
<button type="button" class="btn btn-primary" ng-click="email()">Email</button>
推荐答案
您可以使用ng-model并通过ng-click传递模型,要获取所选电子邮件的按钮值,请使用角度表达式
You can have a ng-model and pass the model on ng-click, To get the selected email in button value , use angular expression
{{selected.email}}
演示
var app = angular.module('todoApp', []);
app.controller("dobController", ["$scope",
function($scope) {
$scope.names4 = [{
"candidate_name": "Thomas",
"email": "tford0@noaa.gov",
"id": "a35398ac-a974-47f6-9beb-ff9d5a6a8282"
}, {
"candidate_name": "Julie",
"email": "jhansen1@pen.io",
"id": "499e919a-e247-4665-9468-cc56a444848e"
}, {
"candidate_name": "Albert",
"email": "amason2@g.co",
"id": "76f53028-ec26-4b52-b12e-42ba3983ec36"
}];
$scope.email = function(selected) {
alert(selected.email)
}
}
]);
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<title>To Do List</title>
<link href="skeleton.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script src="MainViewController.js"></script>
</head>
<body ng-controller="dobController">
<div class="col-md-20">
<div id="main">
<form class="form-horizontal" role="form">
<label class="control-label col-md-2">Filter List:</label>
<div class="col-md-5">
<select ng-model="selected" ng-options="emp.candidate_name for emp in names4 ">
</select>
</div>
<button type="button" class="btn btn-primary" ng-click="email(selected)">{{selected.email}}</button>
</form>
</div>
</div>
</body>
</html>
这篇关于在Angular中选定的下拉菜单中,如何在按钮值中获得特定的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!