如果不存在,加載angularjs文件是否可能?我正在製作一個基於Angular的小部件,並希望客戶端能夠使用該小部件。 如果角色不在主機頁面上,則不會加載腳本。加載角度如果不存在
我是Angular的新手,我很想學習(掌握)這個驚人的框架。
我發現我想要的jQuery變體。如果有人有段或網站,他可以參考我的(更好的)角度版本,它會幫助我很多
下面是代碼:
<script type="text/javascript">
(function() {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function() { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else { // Other browsers
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function($) {
// We can use jQuery 1.4.2 here
});
}
})(); // We call our anonymous function immediately
</script>
預先感謝您
你可以做到這一點非常相似的方式,但做一次檢查按@Chankey帕塔克然後在'scriptLoadHandler()'你會ahve通過手動自舉文件'angular.bootstrap(文檔處理的角度,[ 'yourAppName'])' – maurycy