我正在尝试从ng-Dialog传递值。
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>
单击表格内的拒绝按钮,对话框即将出现。
控制器:
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");
});
}
我注意到按钮点击时未传递ID:rejectEmployeeButton(reservation.employee.id)
在发布对话框文本区域内的数据时也会遇到类似的问题。但是一旦我找到一个解决方案来点击按钮点击值,我就能搞清楚。
我做错了什么?
答案 0 :(得分:0)
更好的方法是传递对象并访问控制器内的id,
ng-click="rejectEmployeeButton(reservation)"
控制器:
$scope.rejectEmployeeButton = function (reserObj) {
var id = reserObj.employee.id;
}
答案 1 :(得分:0)
您可以为OpenDialoge定义控制器并在该控制器函数内写入所有代码。
ngDialog.open({
template: 'templateId',
closeByDocument: true,
closeByEscape: true,
controller:function()
{
this.rejectEmployeeButton = function (id) {
rejectEmployeeButton(id);
};
},
rejectEmployeeButton=function()
{
// Do somthing open dialog
}
你可以这样试试。