1.angular 初始化流程 function(window, document, undefined) { //定位到4939行,這裏是angularjs開始執行初始化的地方,見代碼 bindJQuery(), publishExternalAPI(angular), jqLite(document).ready(function() { angularInit(document, bootstrap) }) //bindJQuery方法是檢查是否引用jquery,沒有的話jqlite就用自己自帶的,不然切換到jquery中去.這個好理解 publishExternalAPI這個方法是綁定一些公共的方法到angular下面,這些是能夠在網站中訪問到的,像forEach,copy等公共方法,還有一個重要的任務就是初始化angular核心的模塊,publishExternalAPI在465行,如今咱們來分析裏面的一些重要的代碼 }(window, document), !angular.$$csp() && //我的理解爲此處angular的標誌變量未定義 //下面就是爲將angular找到head 對一些指令追加css樣式 angular.element(document).find("head").prepend('<style type="text/css">@charset "UTF-8"; [ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\\:form{display:block;}. ng-animate-start{clip:rect(0,auto,auto,0);-ms-zoom:1.0001;}. ng-animate-active{clip:rect(-1px,auto,auto,0);-ms-zoom:1;}</style>')
bindJQuery 方法解析 function bindJQuery() { var originalCleanData; if (bindJQueryFired) { return; } /***********************************若是有引入jquery,就使用jquery ***********************/ // bind to jQuery if present; var jqName = jq(); jQuery = window.jQuery; // use default jQuery. if (isDefined(jqName)) { // `ngJq` present 若是有引入jquery,就使用jquery jQuery = jqName === null ? undefined : window[jqName]; // if empty; use jqLite. if not empty, use jQuery specified by `ngJq`. } // Use jQuery if it exists with proper functionality, otherwise default to us. // Angular 1.2+ requires jQuery 1.7+ for on()/off() support. // Angular 1.3+ technically requires at least jQuery 2.1+ but it may work with older // versions. It will not work for sure with jQuery <1.7, though. if (jQuery && jQuery.fn.on) { jqLite = jQuery; extend(jQuery.fn, { scope: JQLitePrototype.scope, isolateScope: JQLitePrototype.isolateScope, controller: JQLitePrototype.controller, injector: JQLitePrototype.injector, inheritedData: JQLitePrototype.inheritedData }); // All nodes removed from the DOM via various jQuery APIs like .remove() // are passed through jQuery.cleanData. Monkey-patch this method to fire // the $destroy event on all removed nodes. originalCleanData = jQuery.cleanData; jQuery.cleanData = function(elems) { var events; if (!skipDestroyOnNextJQueryCleanData) { for (var i = 0, elem; (elem = elems[i]) != null; i++) { events = jQuery._data(elem, "events"); if (events && events.$destroy) { jQuery(elem).triggerHandler('$destroy'); } } } else { skipDestroyOnNextJQueryCleanData = false; } originalCleanData(elems); }; } else { /***********************************若是沒有引入jquery,就使用angular 自帶的JQlite***********************/ jqLite = JQLite; } angular.element = jqLite; // Prevent double-proxying. bindJQueryFired = true; }