twitter-bootstrap 加载时的 Bootstrap-angular-ui 模态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19657323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap-angular-ui modal on load
提问by Hossain Muctadir
I am using bootstrap-angular-ui-modalfor a site I am working on. The code I am using to open the modal
我正在为我正在处理的网站使用bootstrap-angular-ui-modal。我用来打开模态的代码
$modal.open(
{
templateUrl: '/home/template',
controller: myCtrl,
resolve: {
data: function () {
return data;
}
}
});
Everything is working fine. But I need to find a way to execute some code after modal is loaded. I tried different things but can't make them work. Some of things I tried
一切正常。但是我需要找到一种在加载模态后执行一些代码的方法。我尝试了不同的东西,但不能让它们工作。我尝试过的一些事情
In template I did
在模板中我做了
<script>
document.onload = function () {
console.log('opened');
};
</script>
I also found there is a promise for the angular modal object named openned. I tried to
我还发现有一个名为 openned 的角度模态对象的承诺。我尝试过了
modalInstance.opened.then(function(){console.log('hello')});
not working either. I can use some help here.
也不工作。我可以在这里使用一些帮助。
采纳答案by Hossain Muctadir
This is definitely not a good solution, but at least worked for me. I just added a timeout before executing the desired function,
这绝对不是一个好的解决方案,但至少对我有用。我只是在执行所需的功能之前添加了一个超时,
modalInstance.opened.then(
$timeout(function() {
console.log('hello');
}, delay));
回答by Hossain Muctadir
UI-bootstraps modal has a resultresolve.
UI-bootstraps modal 有一个result解决方案。
"opened" - a promise that is resolved when a modal gets opened after downloading content's template and resolving all variables
“opened” - 在下载内容模板并解析所有变量后打开模态时解析的承诺
or
或者
Use ng-init. Create a div inside your template file:
使用 ng-init。在模板文件中创建一个 div:
<div ng-init="func()"></div>
回答by user247702
Since version 0.13.0, there's a renderedpromise you can use.
从版本 0.13.0 开始,rendered您可以使用一个承诺。
rendered(Type:promise)- Is resolved when a modal is rendered.
rendered(类型:promise)-当一个模式被渲染得到解决。
Example:
例子:
this.modalInstance.rendered.then(function () {
console.log("modal is rendered");
});
回答by jdmcnair
If you're wanting to do something after the DOM is loaded, it's best to do that sort of thing inside a directive. See here: http://docs.angularjs.org/guide/directive#creating-a-directive-that-manipulates-the-dom
如果你想在 DOM 加载后做一些事情,最好在指令中做那种事情。见这里:http: //docs.angularjs.org/guide/directive#creating-a-directive-that-manipulates-the-dom
You could mark your modal body (or something inside the modal) with your directive attribute, then create the directive like so:
你可以用你的指令属性标记你的模态体(或模态内的东西),然后像这样创建指令:
App.directive('myDirective', function($timeout) {
function link(scope, element, attrs) {
$timeout(function () {
// stuff to do after DOM load here
});
}
return {
link: link
};
});

