angular.bootstrap后unbootstrap已经启动? [英] unbootstrap after angular.bootstrap has been initiated?

查看:500
本文介绍了angular.bootstrap后unbootstrap已经启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有麻烦试图重新编译应用程序的角度。

Having trouble trying to recompile angular app.

有没有一种方法调用angular.bootstrap后unbootstrap?

Is there a way to unbootstrap after calling angular.bootstrap?

在我做angular.bootstrap已经自举时,会导致错误

Once I do angular.bootstrap when already bootstrapped, causes errors

谢谢!

推荐答案

这似乎并不像角的目的是要做到这一点,我想不出什么好理由,你为什么会想(但也许你做的) 。这就是说,从看 angular.js源code
 这似乎是唯一的出路,这工作将删除您最初从DOM自举的元素,然后重新添加它,然后再次尝试的Bootstrap。

It does not seem like angular was designed to do this, and I can't think of any good reason why you would want to (but maybe you do). That said, from looking at the angular.js source code it seems like the only way that this could work would be to remove the element you originally bootstrapped from the DOM and then re-add it and then try bootstraping again.

下面是一个自举一个超级简单的应用程序,然后在5秒后概念的的jsfiddle 证明再次引导自身。我会非常犹豫,做这样的事情在一个复杂的应用程序,但它似乎工作。

Here's a jsfiddle proof of concept that bootstraps a super simple app and then after 5 seconds bootstraps itself again. I'd be extremely hesitant to do something like this on a complex app but it does seem to work.

 var bootstrapApp = function(appDiv) {
    var isSecondTime = false;
    if (appDiv) {
        document.body.removeChild(appDiv);
        isSecondTime = true;
    }
    appDiv = document.createElement('div');
    appDiv.id = "myApp";
    appDiv.innerHTML = (isSecondTime ? ' 2nd bootstrap': ' 1st bootstrap') + template.innerHTML;
    document.body.appendChild(appDiv);
    angular.bootstrap(angular.element(appDiv), ['myApp']);

    return appDiv;
}

var createdAppDiv = bootstrapApp(null);

setTimeout(function() {
    console.log("try boostraping again");
    bootstrapApp(createdAppDiv);
}, 5000);

这篇关于angular.bootstrap后unbootstrap已经启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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