我試圖從ng-Dialog傳遞值。在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)
也面臨着類似的問題,而發佈這是該對話框中的文本區域裏面的數據。但是一旦我找到一個解決方案來傳遞按鈕點擊的值,我就可以想通了。
我在做什麼錯了?
「無法讀取的未定義的屬性‘員工’」 ......沒有得到對話框 – Phoenix
@Phoenix這是問題,檢查被傳遞什麼裏面的對象。您的預訂對象可能是空的 – Sajeetharan
不,它不是。 result.data:數組[1] : 對象 帳戶 : 對象 createdOn : 「2017-02-09T12:31:07.9387838」 僱員 : 對象 ID :此話 : 「測試」 reservedFrom : 「2017-02-27T00:00:00」 reservedTill : 「2017-02-28T0 0:00:00" __proto__ : 對象 長度 : __proto__ : 數組[0] 鍵:<不可> – Phoenix