通过开放模态函数传递数据 Angular uibModal
Passing data through open modal function Angular uibModal
我想弄清楚如何在弹出时将 unit_number
传递到模式中。我对 Angular 很陌生,我对 resolve:
和 group:
正在做的事情以及如何将 unit_number 包含在 return 中有点困惑]声明。
$scope.openTenantModal = function (unit_number) {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/addtenantmodal.html',
controller: 'AddTenantModalCtrl',
size: 'large',
resolve: {
group: function () {
return $scope.group;
}
}
});
modalInstance.result.then(function () {
}, function () {
});
};
只需在解析对象 unitNumber
中添加一个 属性 并从中返回 unit_number
值的函数。这样您就可以通过在控制器工厂函数中注入 unitNumber
依赖项来获取 AddTenantModalCtrl
中的 unit_number
值。
resolve: {
group: function () {
return $scope.group;
},
unitNumber: function(){
return unit_number
}
}
Note: Don't directly do unitNumber: unit_number
, because when you have that, angular DI system will try to search the dependency
with name unit_number
(value) and It will try to evaluate it as
function. Resultant you will get $injector
error in console.
您正在使用 ui-bootstrap
Bootstrap components written in pure AngularJS
要将变量传递给模态控制器,您需要使用
resolve: {
A: function() {
return 'myVal'
}
}
然后你可以通过注入它
从模态的控制器访问那个变量'A'
controller: ['A', function(A) {
// now we can add the value to the scope and use it as we please...
$scope.myVal = A;
}]
查看:https://angular-ui.github.io/bootstrap/#/modal
解决:
Members that will be resolved and passed to the controller as locals; it is equivalent of the resolve property in the router.
组只是一个成员(可以是任何你选择的)
我想弄清楚如何在弹出时将 unit_number
传递到模式中。我对 Angular 很陌生,我对 resolve:
和 group:
正在做的事情以及如何将 unit_number 包含在 return 中有点困惑]声明。
$scope.openTenantModal = function (unit_number) {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/addtenantmodal.html',
controller: 'AddTenantModalCtrl',
size: 'large',
resolve: {
group: function () {
return $scope.group;
}
}
});
modalInstance.result.then(function () {
}, function () {
});
};
只需在解析对象 unitNumber
中添加一个 属性 并从中返回 unit_number
值的函数。这样您就可以通过在控制器工厂函数中注入 unitNumber
依赖项来获取 AddTenantModalCtrl
中的 unit_number
值。
resolve: {
group: function () {
return $scope.group;
},
unitNumber: function(){
return unit_number
}
}
Note: Don't directly do
unitNumber: unit_number
, because when you have that, angular DI system will try to search the dependency with nameunit_number
(value) and It will try to evaluate it as function. Resultant you will get$injector
error in console.
您正在使用 ui-bootstrap
Bootstrap components written in pure AngularJS
要将变量传递给模态控制器,您需要使用
resolve: {
A: function() {
return 'myVal'
}
}
然后你可以通过注入它
从模态的控制器访问那个变量'A'controller: ['A', function(A) {
// now we can add the value to the scope and use it as we please...
$scope.myVal = A;
}]
查看:https://angular-ui.github.io/bootstrap/#/modal
解决:
Members that will be resolved and passed to the controller as locals; it is equivalent of the resolve property in the router.
组只是一个成员(可以是任何你选择的)