zoukankan      html  css  js  c++  java
  • compile and link

    <!DOCTYPE html>
    <html data-ng-app="myApp">
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body data-ng-controller="myAppCtrl">
    <data-compile-and-link>{{name}}</data-compile-and-link>
    <level-one>
        <level-two>
            <level-three>
                Hello
            </level-three>
        </level-two>
    </level-one>
    </body>
    <script src="angular.js"></script>
    <script>
        var myApp = angular.module('myApp', []);
        myApp.controller('myAppCtrl', function ($scope) {
            $scope.name = 'Jackey';
        });
    
        //
        /* myApp.directive('compileAndLink', function () {
         return {
         restrict: 'E',
         controller: function ($scope, $element) {
         console.log('controlle:begin...');
         },
         compile: function (cElement, cAttrs) {
         console.log('compile:begin...');
         return {
         pre: function (preScope, preElement, preAttrs) {
         console.log('pre link:begin...');
         },
         post: function (postScope, postElement, postAttrs) {
         console.log('post link:begin...');
         }
         };
         },
         link: function (linkScope, linkEelemnt, linkAttr) {
         console.log('link begin...');
         }
         };
         });*/
    
        //result:
        //            compile:begin...
        //            index.html:21 controlle:begin...
        //            index.html:27 pre link:begin...
        //            index.html:30 post link:begin...
        //我们可以知道:directvie的先后顺序是compile - controller - pre - post 。。。
        //link没有执行,是因为link就是compile里面的post link了。
    
        function createDirective(name) {
            return function () {
                return {
                    restrict: 'E',
                    compile: function (tElem, tAttrs) {
                        console.log(name + ': compile');
                        return {
                            pre: function (scope, iElem, iAttrs) {
                                console.log(name + ': pre link');
                            },
                            post: function (scope, iElem, iAttrs) {
                                console.log(name + ': post link');
                            }
                        }
                    }
                }
            }
        }
    //    myApp.directive('levelOne', createDirective('levelOne'));
    //    myApp.directive('levelTwo', createDirective('levelTwo'));
    //    myApp.directive('levelThree', createDirective('levelThree'));
    
        //result:
        //    levelOne: compile
        //    levelTwo: compile
        //    levelThree: compile
        //    levelOne: pre link
        //    levelTwo: pre link
        //    levelThree: pre link
        //    levelThree: post link
        //    levelTwo: post link
        //    levelOne: post link
    
        function createDirective(name){
            return function(){
                return {
                    restrict: 'E',
                    compile: function(tElem, tAttrs){
                        console.log(name + ': compile => ' + tElem.html());
                        return {
                            pre: function(scope, iElem, iAttrs){
                                console.log(name + ': pre link => ' + iElem.html());
                            },
                            post: function(scope, iElem, iAttrs){
                                console.log(name + ': post link => ' + iElem.html());
                            }
                        }
                    }
                }
            }
        }
        myApp.directive('levelOne', createDirective('levelOne'));
        myApp.directive('levelTwo', createDirective('levelTwo'));
        myApp.directive('levelThree', createDirective('levelThree'));
    
    //    levelOne: compile =>
    //    <level-two>
    //    <level-three>
    //    Hello
    //    </level-three>
    //    </level-two>
    //
    //    levelTwo: compile =>
    //    <level-three>
    //    Hello
    //    </level-three>
    //
    //    levelThree: compile =>
    //    Hello
    //
    //    levelOne: pre link =>
    //    <level-two>
    //    <level-three>
    //    Hello
    //    </level-three>
    //    </level-two>
    //
    //    levelTwo: pre link =>
    //    <level-three>
    //    Hello
    //    </level-three>
    //
    //    levelThree: pre link =>
    //    Hello
    //
    //    levelThree: post link =>
    //    Hello
    //
    //    levelTwo: post link =>
    //    <level-three>
    //    Hello
    //    </level-three>
    //
    //    levelOne: post link =>
    //    <level-two>
    //    <level-three>
    //    Hello
    //    </level-three>
    //    </level-two>
    
        //留意post link是一个反向的解析
    </script>
    
    </html>
  • 相关阅读:
    mysql常见的hint
    SQL优化:一篇文章说清楚Oracle Hint的正确使用姿势
    Oracle中常见的Hint(一)
    oracle中hint 详解
    Oracle hint 详解
    neo4j简单学习
    Maven的pom.xml文件结构之基本配置parent和继承结构
    使用TASM编译COFF格式和连接
    使用双引擎,让kbmmw 的客户端访问更方便(既给浏览器做服务,也给桌面程序做服务)
    成大事者不纠结(碰到难办的事情的时候,要就事论事,专注当下,放下过去,不忧未来,也不要记仇。防范之举要节制。是做事情的其中一种策略,而且还要分场合)
  • 原文地址:https://www.cnblogs.com/lihaozhou/p/4561981.html
Copyright © 2011-2022 走看看