2015年11月8日 星期日

angularjs complied order ,structure


http://stackoverflow.com/questions/20663076/angularjs-app-run-documentation
















Here's the calling order:
  1. app.config()
  2. app.run()
  3. directive's compile functions (if they are found in the dom)
  4. app.controller()
  5. directive's link functions (again, if found)
Here's a simple demo where you can watch each one executing (and experiment if you'd like).
============
very good example:
============
index.html:54 app config
index.html:50 app run
index.html:37 directive setup
index.html:39 directive compile
index.html:58 app controller
index.html:45 directive link


        <script>
                var myApp = angular.module('myApp', []);
                myApp.factory('aProvider', function() {
                   console.log("factory");
                });

                myApp.directive("test1", function() {
                    console.log("directive setup");
                    return {
                        compile: function() {console.log("directive compile");}
                    }
                });

                myApp.directive("test2", function() {
                    return {
                        link: function() {console.log("directive link");}
                    }
                });

                myApp.run(function() {
                    console.log("app run");
                });

                myApp.config( function() {
                    console.log("app config");
                });

                myApp.controller('myCtrl', function($scope) {
                    console.log("app controller");
                });
        </script>

================



沒有留言:

張貼留言