从 init 中不显示模态元素



All,

我有一个通过路由器加载的模态元素,当我尝试显示模态时出现问题,尽管 URL 已正确更改,但它没有显示。如果我调用 init 发生在延迟一段时间的$timeout内,则不会出现问题。我不想指定延迟时间,任何建议,以取消$timeout和延迟时间。

这是我的代码

(function init() {
$scope.model = {
//    email specific info being set here
};

$timeout(function() {
modalElement = angular.element('[ng-controller="mycontroller"] .modal');
modalElement.modal('show');
},50); // without this delay the modal element is not shown
})();

请注意,此问题仅在刷新后首次加载模式时发生,一旦在缓存中设置了模式,此问题就不会发生,可能是获取模式的延迟导致此问题。

请问有什么建议吗?

used the interval and tried to check the availability of the modal object before invoking the show, did the trick. hence it can be like 
var test =  $interval(function() {
modalElement = angular.element('[ng-controller="mycontroller"] .modal');
if(modalElement.length ==1)
{
modalElement.modal('show');
$interval.cancel(test);
}
},50); // without this delay the modal element is not shown

最新更新