Angular Directives Notes – Priorities

compile and prelink functions of directives with lower priority are run last, whereas postlink functions of directives with lower priority are run first. Lower the number lower the priority.

Simple Example

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="lib/angular.js"></script>
    <script src="js/directives_u.js"></script>
    <script>
        angular.module('u_directives').directive('bbDir1', function(){
            return{
                priority:02,
                compile:function(){
                    console.log('compile-dir1');
                    return {
                        pre:function(){
                            console.log('pre-dir1');
                        },
                        post:function(){
                            console.log('post-dir1');
                        }
                    }
                }
            }}).directive('bbDir2', function(){
            return{
                priority:01,
                compile:function(){
                    console.log('compile-dir2');
                    return {
                        pre:function(){
                            console.log('pre-dir2');
                        },
                        post:function(){
                            console.log('post-dir2');
                        }
                    }
                }
            }})
    </script>
</head>
<body ng-app="u_directives">
    <div bb-dir1 bb-dir2></div>
</body>
</html>

 

Advertisements

One thought on “Angular Directives Notes – Priorities

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s