AngularJS - 在一个对话框打开控制器(模板动态加载) [英] AngularJS - open controller in a dialog (template loaded dynamically)

查看:260
本文介绍了AngularJS - 在一个对话框打开控制器(模板动态加载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩弄AngularJS。我使用一个控制器和一个templateUrl有事情做自动的:)
目前,该布局具有唯一< D​​IV NG-视图>< / DIV>所有的东西都装入其中指令。

我想开模态(引导或jQuery UI的,无所谓)和负载的没有的(模态的体内)由下式给出指定控制器链接。

就像每一个环节打开(加载模板和放大器;完成所有的DOM编辑&安培;连接),我的主要 NG-视图里面,我想一些链路的模态内以打开

我已经签出了什么AngularStrap和角度的UI引导所提供的,并且他们都没有什么有我要找的。

AngularStrap可以获取新的部分模板,但不执行新控制器。

有没有什么解决方案/片断执行莫代尔/对话框?

里面的第二个控制器
解决方案

这里有一个plnkr 的演示使用角+ UI的引导启动对话与它自己的模板和控制器。

这听起来像你是一个有点困惑控制器和DOM之间的关系。控制器不生活在里面的DOM,事实上,我们正在试图保持两件事情是不同的。相反,DOM是与被控制的范围$ ...关联(你猜对了...)控制器。

因此​​,在该示例中,控制器被当对话元素添加到DOM装入,但是,在任何有意义的方式,控制器不是对话框中打开。该对话框可以很容易地通过更换DialogCtlDemoCtl在演示的第17行。我想说的是,控制器和对话是独立的。对话框不执行控制器,相反,它们是 $范围一个manged耗时。

更新:我刚刚发现的例子是有点马车,如果你关闭该对话框,然后尝试重新打开它,显示模式,但不是对话框。我想现在整理了这一点,我真的不知道发生了什么事......

更新2:我觉得无法加载对话框具有模板缓存做。在这个plnkr 你看,我添加了一个缓存克星上查询字符串,对话框重新加载的,但模态背景没有。在UI-引导页面上的例子可以加载和放大器;重载没有问题,但他们用的是硬codeD模板(而不是一个模板URL)。我是不是能够得到plnkr该工作无论是。哦,对前沿工作的乐趣: - /

更新3:我无法弄清楚是怎么回事,但张贴了这个问题,寻求帮助<一个href=\"http://stackoverflow.com/questions/16941770/opening-the-same-dialog-multiple-times-with-dialog\">Opening同一对话框中多次使用$对话框

I'm playing around with AngularJS. I'm using a controller and a templateUrl to have things done automagically :) Currently the layout has only <div ng-view></div> directive into which all the things are loaded.

I'd like to open the modal (Bootstrap or jQuery UI, doesn't matter) and load there (inside a modal's body) the controller specified by given link.

Just like every link "opens" (loads the template & does all the DOM compilation & linking) inside my main ng-view, I'd like some of the links to open inside the modal.

I've checked out what AngularStrap and Angular-UI Bootstrap has to offer, and neither of them has what I'm looking for.

AngularStrap can obtain new partial template, but doesn't execute the new controller.

Is there any solution / snippet that executes the second controller inside Modal/Dialog?

解决方案

Here's a plnkr that demonstrates using the angular + ui-bootstrap to launch a dialog with it's own template and controller.

It sounds like you are a bit confused about the relationship between a controller and the DOM. The controller doesn't live inside the DOM, in fact, we are trying to keep the 2 things distinct. Rather, the DOM is associated with a $scope which is controlled by a... (you guessed it...) controller.

So, in the example, the controller is loaded when the dialog elements are added to the DOM, but, the controller isn't "opened in the dialog" in any meaningful way. The dialog could just as easily use the same controller that the main app is using, by replacing "DialogCtl" with "DemoCtl" on line 17 of the demo. What I'm trying to say is that the controller, and the dialog are independent. Dialogs aren't executing controllers, rather, they are consuming $scope manged by one.

UPDATE: I just found out the example is a bit buggy, if you dismiss the dialog and then try re-opening it, the modal is displayed but not the dialog. I'm trying to sort that out now, i'm not really sure what's going on...

UPDATE 2: I think the inability to reload the dialog has to do with template caching. In this plnkr you see that I add a 'cache buster' onto the querystring, and the dialog reloads, but the modal backdrop doesn't. The example on the ui-bootstrap page can be loaded & reloaded without issue, but they are using a hard-coded template (rather than a template url). I wasn't able to get that working in plnkr either. Oh, the joys of working on the bleeding edge :-/

UPDATE 3: I can't figure out what's going on, but posted this question for help Opening the same dialog multiple times with $dialog

这篇关于AngularJS - 在一个对话框打开控制器(模板动态加载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆