单向绑定原理

 

 

 从下到上除开开头和结尾,分为4部分

第一部分:执行$rootscope.$applay()

injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
function bootstrapApply(scope, element, compile, injector) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
}]
);

解析$apply源码:$apply: function(expr) { try {

beginPhase('$apply');
try {
return this.$eval(expr);
} finally {
clearPhase();
}
} catch (e) {
$exceptionHandler(e);
} finally {
try {
$rootScope.$digest();
} catch (e) {
$exceptionHandler(e);
throw e;}}},

第二部分:

case NODE_TYPE_TEXT: /* Text Node */
if (msie === 11) {
// Workaround for #11781
while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === NODE_TYPE_TEXT) {
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
node.parentNode.removeChild(node.nextSibling);
}
}
addTextInterpolateDirective(directives, node.nodeValue);
break;

function addTextInterpolateDirective(directives, text) {
var interpolateFn = $interpolate(text, true);
if (interpolateFn) {
directives.push({
priority: 0,
compile: function textInterpolateCompileFn(templateNode) {

第三部分:link阶段

 return function textInterpolateLinkFn(scope, node) {   ||||||||||||||     $watch: function(watchExp, listener, objectEquality, prettyPrintExpression) {

 

 $$watchDelegate: function(scope, listener) 

第四部分:

 

 $digest: function()

 

posted @ 2019-09-29 13:51  onyli  阅读(186)  评论(0)    收藏  举报