0

问题

dialog在我的应用程序中使用 UI Bootstrap 的服务,该服务创建模态对话框,我在外部使用以下方法执行此操作$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>

我的对话框处理一个routeroute是主模型中的子模型)的编辑,因此我想将该路径传递给对话框,以便它像对待自己的模型一样对待它,而不需要对外部模型一无所知。

我对这个问题的最初猜测是将路由参数分配给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 的做事方式

我还发现这篇文章说我应该为此目的使用服务,但对于这样的小问题,这个解决方案似乎有点过头了。

问题

使用上述场景将值从外部控制器传递到内部控制器的角度方式是什么。

谢谢

4

1 回答 1

2

您可以使用“解决” -

var dialog = $dialog.dialog({
  resolve: {route: function(){return "route"}}
});

稍后您可以在控制器中注入“路由”值

.controller("SomeCtrl",function(route){

})
于 2013-06-28T08:38:07.223 回答