[英]Pass a value on button click inside an ng-Dialog
I am trying to pass value from an ng-Dialog. 我试图从ng-Dialog传递值。
HTML: HTML:
<div class="col-md-12" style="text-align:center" ng-controller="getReservationController">
<label ng-show="!data.length" >No reservations found!</label>
<div class="widget widget-table action-table" ng-repeat="reservation in data">
<div ng-show="data.length" class="widget-content table-container" style="overflow:auto">
<table ng-table="reservationsList" class="table table-striped table-bordered" wt-responsive-table style="font-size: smaller;text-align:center; display:block;overflow-x:scroll">
<tr >
<td data-title="'#'">{{ $index+1 }}</td>
<td data-title="'Name'" ui-sref="employee.edit({id: reservation.employee.id})" sortable="'employee.name'" filter="{ 'employee.name': 'text' }" style="width:230px">
<a ui-sref="employee.edit({id: employee.id})" tooltip="View or Edit employee" tooltip-trigger tooltip-animation="false" tooltip-placement="bottom" style="color:#23527c">{{reservation.employee.firstName +""+reservation.employee.lastName}}</a>
</td>
<td data-title="'Reject'">
<a tooltip="Reject employee" tooltip-trigger tooltip-animation="false" tooltip-placement="bottom" data-placement="left" data-toggle="tooltip" data-original-title="reject" ng-show="data.currentUser==reservation.account.programManager.id || data.role == 'HR'" ng-click="rejectEmployee"><svg class="glyph stroked cancel"><use xlink:href="#stroked-cancel" /></svg></a>
</td>
</tr>
</table>
</div>
<script type="text/ng-template" id="templateId">
<div class="media-body act-media-body">
<h5 class="success" style="color:red">Are you sure you want to reject this reservation?</h5>
If yes, please specify reason : <textarea type="text" ng-model="reservation.account.name" placeholder="test" style="height:100px;resize: none;"/>
<button class="ngdialog-button" ng-click="rejectEmployeeButton(reservation.employee.id)">Confirm</button>
</div>
</script>
</div>
</div>
On click of Reject button inside the table, the Dialog is coming up. 单击表内的“拒绝”按钮时,将弹出对话框。
Controller : 控制器:
myApp.controller('getReservationController', ['$scope', 'reservationServices', 'dataTable', '$rootScope', '$location', '$filter', 'ngDialog', '$window', function ($scope, reservationServices, dataTable, $rootScope, $location, $filter, ngDialog, $window) {
reservationServices.getReservations().then(function (result) {
$scope.data = result.data;
$scope.rejectEmployee = function () {
ngDialog.open({
template: 'templateId',
closeByDocument: true,
closeByEscape: true,
preCloseCallback: function (value) {
},
scope: $scope
});
}
$scope.rejectEmployeeButton = function (id) {
reservationServices.rejectEmployee(id).then(function (result) {
ngDialog.openConfirm({
template:
'<p>Rejected the employee!</p>',
plain: true,
className: 'ngdialog-theme-default'
})
$location.path("/talents");
});
}
I noticed that the Id is not getting passed upon button click : rejectEmployeeButton(reservation.employee.id)
我注意到按钮单击时未传递ID: rejectEmployeeButton(reservation.employee.id)
Also faces a similar issue while posting the data which is inside the text area in the dialog. 在对话框中的文本区域内发布数据时,也面临类似的问题。 But I can figure it out once i find a solution to pass the value on button click. 但是,一旦我找到一种解决方案来传递按钮单击值,我就可以弄清楚。
What am i doing wrong? 我究竟做错了什么?
Better way is to pass the object and access the id inside the controller, 更好的方法是传递对象并访问控制器内部的ID,
ng-click="rejectEmployeeButton(reservation)"
Controller: 控制器:
$scope.rejectEmployeeButton = function (reserObj) {
var id = reserObj.employee.id;
}
You can define controller for OpenDialoge and write all code inside that controller function. 您可以为OpenDialoge定义控制器,并在该控制器函数内编写所有代码。
ngDialog.open({
template: 'templateId',
closeByDocument: true,
closeByEscape: true,
controller:function()
{
this.rejectEmployeeButton = function (id) {
rejectEmployeeButton(id);
};
},
rejectEmployeeButton=function()
{
// Do somthing open dialog
}
You can try like this. 您可以这样尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.