【发布时间】:2013-06-28 16:38:07
【问题描述】:
问题
我在我的应用程序中使用 UI Bootstrap 的 dialog 服务,该服务创建模态对话框,我在外部 $scope 上使用以下方法:
$scope.showRouteEditDialog = function (template, route) {
// argument `route` is not currently used
var dialog = $dialog.dialog({
backdrop: true,
keyboard: false,
backdropClick: true,
templateUrl: template,
controller: 'RouteController'
});
dialog.open().then(function(result) {
alert(result); // This line is called when dialog is closed
});
}
此方法稍后会使用以下标记从局部视图中调用
<a href="#" ng-click="showRouteEditDialog('Templates/Content/Timeline/Item/Editor.html', route)"><i class="halflings-icon edit"></i></a>
我的对话框处理 route 的编辑(route 是主模型中的子模型),因此我想将该路径传递给对话框,以便它像对待自己的模型一样对待它而不知道任何关于外部模型。
我对这个问题的最初猜测是将路由参数分配给dialog 变量,类似于dialog.route = route,然后在控制器中使用以下代码:
Application.controller('RouteController', ['$scope', 'dialog', function ($scope, dialog) {
// `dialog` is our dialog and it is injected with injector
doSomethingWith(dialog.route)
}]);
虽然这种方法会产生依赖并且看起来不像 Angular 的做事方式
我还发现 this post 说我应该为此目的使用服务,但对于这样的小问题,这种解决方案似乎有点过头了。
问题
在上述情况下,将值从外部控制器传递到内部控制器的角度方式是什么。
谢谢
【问题讨论】:
标签: angularjs angular-ui-bootstrap