如果已经有人问过这个问题,我很抱歉,但是是否可以从 Angular 带模态返回数据,如果可以,任何人都可以提供简短的代码片段如何做到这一点?
有一个非常好的选项可以从 Angular-ui 模式返回数据,但我找不到带路。 非常感谢您的解答。
最佳答案
您可以非常轻松地从 angular-strap
模态返回任何数据。
假设您有一些对象,应该在模式提交后更新。例如,您有一个 Controller ,可以弹出您的模式。您所要做的就是定义一些处理程序,该处理程序应该更新您的数据,通过 resolve
选项将此处理程序传递给您的模态,并在模态的 Controller 中调用此处理程序。
例子:
该 Controller 包含用户详细信息并显示更改此数据的模式。
app.controller('userDetailsCtrl', ['$scope', '$modal', function($scope, $modal) {
$scope.userDetails = {
firstName: 'John',
lastName: 'Smith'
};
$scope.showChangeUserDetailsModal = function() {
var options = {
userDetails: angular.copy($scope.userDetails),
submit: function(result) {
$scope.userDetails = angular.copy(result);
}
};
$modal({
controller: 'changeUserDetailsCtrl',
contentTemplate: '', //Here is your template with some input fields
show: true,
resolve: {
options: function() {
return options;
}
}
});
};
}]);
Modal 的 Controller 调用处理程序 submit
,传递 modal 工作的结果。
app.controller('changeUserDetailsCtrl', ['$scope', 'options', function($scope, options) {
$scope.userDetailsDraft = options.userDetails;
$scope.submitChanges = function() {
options.submit($scope.userDetailsDraft);
$scope.$hide(); //Close modal after submit
};
}]);
关于angularjs - 从 Angular 带模态返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33526505/