解决方法
看起来似乎并没有设计角度,我想不出你想要的任何好理由(但也许你这样做).那说,从
angular.js source code看
看起来这种方法可行的唯一方法是删除最初从DOM引导的元素,然后重新添加它,然后再次尝试引导.
看起来这种方法可行的唯一方法是删除最初从DOM引导的元素,然后重新添加它,然后再次尝试引导.
这是一个jsfiddle概念证明,它引导了一个超级简单的应用程序,然后在5秒后再次引导自己.在复杂的应用程序上做这样的事情我会非常犹豫,但似乎确实有效.
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);