我在我的应用程序中使用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)
}]);
虽然这种方法会产生一种依赖性,但看起来并不像角色的做事方式
我还发现this post说我应该为此目的使用服务,但似乎这个解决方案对于这样的小问题来说是一种过度杀伤。
使用上述场景将值从外部控制器传递到内部控制器的角度方式是什么。
谢谢
答案 0 :(得分:2)
您可以使用&#34;解决&#34; -
var dialog = $dialog.dialog({
resolve: {route: function(){return "route"}}
});
以后你可以注入&#34;路线&#34;控制器内部的值
.controller("SomeCtrl",function(route){
})