我必须将几个参数放到模态的控制器上,这样我就可以在[模态中的[u]中显示某些值的值
var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('ctrlTags', function($scope, $uibModal, $log){
// $scope.items = tagsData;
$scope.data = {
repeatSelect: null,
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
$scope.myVar = false;
$scope.show = function () {
$scope.myVar = false;
}
$scope.hide = function () {
$scope.myVar = true;
}
$scope.open = function() {
var modalInstance = $uibModal.open({
templateUrl: 'myModl.html',
controller: 'ModalInstanceCtrl',
resolve: {
param: function () {
$log.log($scope.dt)
return $scope.data;
}
}
});
};
$scope.ok = function() {
$scope.showModal = false;
};
$scope.cancel = function() {
$scope.showModal = false;
};
});
模态的控制器:
app.controller('ModalInstanceCtrl', function($scope, $modalInstance, param) {
// $scope.inputValue = param;
$scope.data = param
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
});
我必须显示除数据之外的更多值。如何将更多参数传递给模态控制器?
答案 0 :(得分:8)
您可以在resovle函数中传递多个数据。
$scope.open = function() {
var modalInstance = $uibModal.open({
templateUrl: 'myModl.html',
controller: 'ModalInstanceCtrl',
resolve: {
param: function () {
$log.log($scope.dt)
return {'data':$scope.data,'yourData' : yourData };
}
}
});
};
app.controller('ModalInstanceCtrl', function($scope, $modalInstance, param) {
// $scope.inputValue = param.data;
$scope.data = param.data;
$scope.yourData = param.yourData;
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
});
答案 1 :(得分:0)
您可以使用param
扩展angular.extend
对象,然后从模板弹出窗口中将其传递给它。在效果上,您只能在弹出控制器和放大器中注入一个param
服务。所有依赖都可以在其中使用。
resolve: {
param: function () {
var param = {};
angular.extend(param, $scope.dt);
angular.extend(param, someOtherData1);
angular.extend(param, someOtherData2);
$log.log(param); //will show you combine data
return param;
}
}