angular js中的可选表格模式弹出窗口
selectable table modal popup in angular js
我正在尝试打开一个带有表格的模式弹出窗口。我该怎么做?在我的app.js中,在打开模态的行的点击事件上,我还想用所选的项值更新一些字段。但我无法使用选定的值进行更新。
my app.js
var tableApp = angular.module('tableApp', ['ui.bootstrap']);
tableApp.controller('tableController', function ($scope,$rootScope, $filter, $modal) {
$scope.filteredPeople = [];
$scope.currentPage = 1;
$scope.pageSize = 10;
$scope.people = [{ id: "1", name: "joe",disable:true },
{ id: "2", name: "bill", disable: true },
{ id: "3", name: "john", disable: true },
{ id: "1", name: "joe", disable: true },
{ id: "2", name: "bill", disable: true },
{ id: "3", name: "john", disable: true },
{ id: "1", name: "joe", disable: true },
{ id: "2", name: "bill", disable: true },
{ id: "3", name: "john", disable: true },
{ id: "1", name: "joe", disable: true },
{ id: "2", name: "bill", disable: true },
{ id: "3", name: "john", disable: true },
{ id: "1", name: "joe" },
{ id: "2", name: "bill", disable: true },
{ id: "3", name: "john", disable: true }];
$scope.getPage = function () {
var begin = (($scope.currentPage - 1) * $scope.pageSize);
var end = begin + $scope.pageSize;
$scope.filteredPeople = $filter('filter')($scope.people, {
id: $scope.idFilter,
name: $scope.nameFilter
});
$scope.totalItems = $scope.filteredPeople.length;
$scope.filteredPeople = $scope.filteredPeople.slice(begin, end);
};
$scope.getPage();
$scope.pageChanged = function () {
$scope.getPage();
};
$scope.open = function () {
$scope.id = generateUUID();
};
$scope.dblclick = function (index) {
for (var i = 0; i < $scope.filteredPeople.length; i++) {
$scope.filteredPeople[i].disable = true;
}
return index.disable = false;
}
$scope.rowSelect = function (rowdata) {
alert(rowdata.name);
}
});
tableApp.controller('DetailModalController', [
'$scope', '$modalInstance', 'item',
function ($scope, $modalInstance, item) {
$scope.item = item;
$scope.dismiss = function () {
$modalInstance.dismiss();
};
$scope.close = function () {
$modalInstance.close($scope.item);
};
}]);
tableApp.directive('myModal', function ($log, $compile) {
var parm = [];
return {
restrict: 'E',
templateUrl: 'modalBase.html',
scope: {
modal: '=',
idF:'='
},
link: function (scope, element, attrs) {
debugger;
parm.name = attrs.idf;
}
//controller: function ($scope) {
// debugger;
// console.log($scope);
// $scope.selected = {
// item: $scope.modal.items[0]
// };
// $scope.ok = function () {
// debugger;
// alert(parm.name);
// $scope.modal.instance.close($scope.selected);
// };
// $scope.cancel = function () {
// $scope.modal.instance.dismiss('cancel');
// };
// $scope.modal.instance.result.then(function (selectedItem) {
// $scope.selected = selectedItem;
// }, function () {
// $log.info('Modal dismissed at: ' + new Date());
// });
//}
};
});
据我所知,您使用angular.ui。我建议您使用$modal
服务,而不是$modalInstance
。使用它,您可以用$modal.open()
调用您的模态实例。而且你不需要在你的控制器中关闭它——在你的模式模板上放置合适的方法,它就会通过它的服务工作
模板:
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<ul>
<li ng-repeat="item in items">
<a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
</li>
</ul>
Selected: <b>{{ selected.item }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="$close()">OK</button>
<button class="btn btn-warning" type="button" ng-click="$dismiss('cancel')">Cancel</button>
</div>
</script>
控制器
var modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
您可以在模式的angular.ui文档中找到更多信息
相关文章:
- Angular$scope在模式窗口内不起作用
- 更改不在引导模式窗口中工作的月份和年份
- TinyMCE全屏不允许出现模式窗口
- 自动模式窗口?/欢迎弹出框
- 推特Boostrap模式窗口-可拖动不工作
- Twitter Boostrap:模式窗口在重新播放模式窗口后不播放视频
- 在Bootstrap模式窗口中打开远程内容
- jQuery模式窗口在内容为“”时不居中;注入“;在飞行中
- 如何在模式窗口弹出窗口中隐藏滚动条
- fancybox将内容更改为模式窗口
- 将值传递给模式窗口中的 JavaScript 函数
- HTML 瞬态模式窗口
- 具有 UI 引导模式窗口的父$scope子
- 如何将参数传递到 UI 路由器状态的模式窗口
- 如何使用引导程序创建模式窗口
- j查询模式窗口,刷新父问题
- 无法将引导模式窗口作为路由打开
- 如何使模式窗口打开动态内容并更改url
- 在引导模式窗口内路由
- 更新面板和模式窗口