{"id":10282,"date":"2016-01-27T16:15:51","date_gmt":"2016-01-27T14:15:51","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=10282"},"modified":"2017-12-19T16:34:35","modified_gmt":"2017-12-19T14:34:35","slug":"angular-js-custom-directives-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/","title":{"rendered":"Angular.js Custom Directives Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>In a <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-transclusion-example\/\" target=\"_blank\">previous example<\/a> we talked about the <code>transclusion<\/code> concept, in terms of Angular directives.<\/p>\n<h2>1.1 What are Directives?<\/h2>\n<p><em>But, what are <a href=\"https:\/\/docs.angularjs.org\/guide\/directive\" target=\"_blank\">directives<\/a> in Angular.js?<\/em><\/p>\n<h3>1.1.1 A definition<\/h3>\n<p>In general, directives is one of the reasons that Angular.js is famous today. They are essentially custom HTML tags and attributes that you can create to do anything one can imagine.<br \/>\n[ulp id=&#8217;LXJcMJZXSsqGXYW8&#8242;]<\/p>\n<h3>1.1.2 Official Definition<\/h3>\n<p><a href=\"https:\/\/docs.angularjs.org\/guide\/directive\" rel=\"external nofollow\" title=\"\" class=\"ext-link\">Directives<\/a> are markers on a <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document_Object_Model\/Introduction\" rel=\"external nofollow\" title=\"\" class=\"ext-link\">DOM<\/a> element (attributes, CSS classes, names of elements, comments) that tell Angular&#8217;s HTML <a href=\"https:\/\/docs.angularjs.org\/api\/ng\/service\/$compile\" rel=\"external nofollow\" title=\"\" class=\"ext-link\">compiler<\/a> to attach a specific behavior to that DOM element (i.e through event listeners), or even to transform the DOM element and its children. Some of the built-in Angular directives are: <a href=\"https:\/\/docs.angularjs.org\/api\/ng\/directive\/ngBind\" rel=\"external nofollow\" title=\"\" class=\"ext-link\"><code>ngBind<\/code><\/a>, <a href=\"https:\/\/docs.angularjs.org\/api\/ng\/directive\/ngModel\" rel=\"external nofollow\" title=\"\" class=\"ext-link\"><code>ngModel<\/code><\/a> and <a href=\"https:\/\/docs.angularjs.org\/api\/ng\/directive\/ngClass\" rel=\"external nofollow\" title=\"\" class=\"ext-link\"><code>ngClass<\/code><\/a>.<\/p>\n<p>In addition to all the built-in Angular.js directives, you can also <a href=\"https:\/\/docs.angularjs.org\/guide\/directive#creating-directives\" rel=\"external nofollow\" title=\"\" class=\"ext-link\">create your own directives<\/a>, by using the <code>.directive<\/code> function.<\/p>\n<p>Such directives look like this, on their html part:<\/p>\n<p><span style=\"text-decoration: underline\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:xml\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;script src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.4.8\/angular.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script src=&quot;second.js&quot;&gt;&lt;\/script&gt;\r\n&lt;body ng-app=&quot;app&quot;&gt;\r\n    &lt;div test-directive&gt;&lt;\/div&gt;\r\n    Hello from page\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>whereas the javascript part is like:<\/p>\n<p><span style=\"text-decoration: underline\"><em>second.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\r\nvar app = angular.module(&quot;app&quot;, []);\r\napp.directive(&quot;testDirective&quot;, function() {\r\n    return {\r\n        restrict : &quot;EA&quot;,\r\n        template : &quot;&lt;h1&gt;Hey, I'm the directive's content!&lt;\/h1&gt;&quot;\r\n    };\r\n});\r\n<\/pre>\n<p>As expected, the output firstly contains the template inserted from the directive and then the actual html content of the page itself:<\/p>\n<figure id=\"attachment_10133\" aria-describedby=\"caption-attachment-10133\" style=\"width: 481px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/1-1.jpg\" rel=\"attachment wp-att-10133\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/1-1.jpg\" alt=\"Figure 1. Sample Directive\" width=\"481\" height=\"168\" class=\"size-full wp-image-10133\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/1-1.jpg 481w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/1-1-300x105.jpg 300w\" sizes=\"(max-width: 481px) 100vw, 481px\" \/><\/a><figcaption id=\"caption-attachment-10133\" class=\"wp-caption-text\">Figure 1. Sample Directive<\/figcaption><\/figure>\n<p><em>Did you notice the transition between the camel-case, used in the js part and the dash (&#8220;-&#8220;), when on html, according to the directive&#8217;s reference?<\/em><\/p>\n<p>There are some points here, according to directives:<\/p>\n<ul>\n<li>A camel-case name must be used for naming a directive (js), but for invoking it (html), a dash (&#8220;-&#8220;) separated name must be used (i.e. <code>testDirective<\/code> -&gt; <code>test-directive<\/code>).<\/li>\n<li>The <code>restrict<\/code> property is used to restrict the directive&#8217;s invocation by some of the existing methods.<\/li>\n<li>The <code>template<\/code> property is used to define the html content that the specified directive will contain.<\/li>\n<\/ul>\n<p>For instance, the legal restrict values are:<\/p>\n<ul>\n<li><code>E<\/code> for element&#8217;s name<\/li>\n<li><code>A<\/code> for attribute<\/li>\n<li><code>C<\/code> for class<\/li>\n<li><code>M<\/code> for comment<\/li>\n<\/ul>\n<p><em>By default, the <code>restrict<\/code> property has a value of <code>EA<\/code>, which means that both element names and attribute names can invoke the directive.<\/em><\/p>\n<p>In addition, here is the full list of all the possible attributes that one could use into a directive, along with their definitions:<\/p>\n<ul>\n<li><code>restrict<\/code> : Determines where a directive can be used.<\/li>\n<li><code>scope<\/code> : Used to create a new child scope or an isolate scope.<\/li>\n<li><code>template<\/code> : Declares the content that will be displayed from the directive; this, except from pure HTML, can always contain Angular features, too (i.e. data-binding expressions, other directives).<\/li>\n<li><code>templateUrl<\/code> : Provides the path to the template that should used by the directive. Optionally, this could contain a DOM element id, when templates are defined in <code>&lt;script&gt;<\/code> tags.<\/li>\n<li><code>controller<\/code> : The controller module that will be associated with the directive template.<\/li>\n<li><code>link<\/code> : A function that is mainly used for DOM manipulation tasks<\/li>\n<li><code>priority<\/code> : specifies the order in which directives are applied to the DOM. (Directives are compiled in priority order, from the highest to lowest. The default priority is &#8220;0&#8221;.)<\/li>\n<li><code>terminal<\/code> : if set to true then the current priority will be the last<br \/>\nset of directives which will execute (any directives at the current priority will still execute as the order of<br \/>\nexecution on same priority is undefined).<\/li>\n<li><code>require<\/code> : require another directive and inject its controller as the fourth argument to the linking function.<\/li>\n<li><code>type<\/code> : string representing the document type used by the markup.<\/li>\n<li><code>transclude<\/code> : compile the content of the element and make it available to the directive.<\/li>\n<li><code>compile<\/code> : deals with transforming the template DOM. (Since most directives do not do<br \/>\ntemplate transformation, it is not used often.)<\/li>\n<\/ul>\n<p>Returning back to our previous small example, what needs to be mentioned is that the directive is restricted to only be invoked either from elements or from attributes ( <code>restrict : \"EA\"<\/code> ), but there&#8217;s not a specific reason -for this example- to include the <code>E<\/code> parameter, as its template (HTML part of the directive) here used as an attribute and specifically, a <code>div<\/code> attribute (<code>&lt;div test-directive&gt;&lt;\/div&gt;<\/code>). That is, the output would be the same as if we only used the <code>A<\/code> value ( <code>restrict: 'A'<\/code> ).<\/p>\n<h2>2. How to build Directives<\/h2>\n<h3>2.1 General Concepts<\/h3>\n<p>In general, there are two ways a directive could be built. The one was depicted in the small example above is the <a href=\"https:\/\/d2eip9sf3oo6c2.cloudfront.net\/pdf\/egghead-io-directive-definition-object-cheat-sheet.pdf\" target=\"_blank\">Directive Definition Object (DDO)<\/a>, which is like the foundation of a directive. It tells Angular how the directive should be handled during the compilation cycle and what it should do. In technical terms, it is an object returned by the directive declaration that provides instructions to the compiler. <\/p>\n<p>Specifically, the DDO is where you can set things such as how it is going to be marked up in the HTML, how its scope is going to interact with the outside world and if it is going to use the existing HTML or load new HTML into the directive&#8217;s content.<\/p>\n<p>The controller function works just like controllers in the rest of your application. It is responsible for initializing the directive&#8217;s state and defining the functionality for it as well.<\/p>\n<p>That was a brief introduction to several of the DDO aspects, also declared in the previous&#8217; section relative list of attributes and is proposed for common, daily-usage of directives, which means that for more advanced concepts the above DDO concepts or even the example previously displayed, are not enough. Here come the <code>$compile<\/code> and <code>$link<\/code> functions.<\/p>\n<h3>2.2 The $compile and $link functions<\/h3>\n<p>If you are in the need of a more complex behavior inside your directive (=something that cannot be implemented  with an HTML template), the <code>$compile<\/code> and <code>$link<\/code> functions come to the rescue. In general, these functions define how the directive is to modify the HTML markup that matched the directive.<\/p>\n<p>The <code>$compile<\/code> function allows the directive to manipulate the DOM before it is compiled and linked thereby, allowing it to CRUD -if I may say- (ok, just kidding: <b>add\/change\/remove<\/b>) directives, as well as, add\/change\/remove other DOM elements. It is called once for each occurence of the directive in the HTML page. The <code>$compile<\/code> function finishes its execution, by returning the <code>$link<\/code> function<\/code>.<\/p>\n<p>The <code>$link<\/code> function is called every time the element is about to be bound to data in the <code>$scope<\/code> object. The concept is that you add the <code>$compile<\/code> function to the DDO and it has to return the <code>$link<\/code> function when executed.<\/p>\n<p>In general, here is the standard format of that two:<\/p>\n<pre class=\"brush:js\">\r\ndirective.compile = function(element, attributes) {\r\n    \/\/ One-time element configuration.\r\n\r\n    var linkFunction = function($scope, element, atttributes) {\r\n        \/\/ Bind element to data in $scope.\r\n    }\r\n\r\n    return linkFunction;\r\n}\r\n<\/pre>\n<h3>2.3 Link function Example<\/h3>\n<p>Before displaying a simple example of the <code>$link<\/code> function, what should be initially mentioned is the fact that there are many times that the <code>$compile<\/code> function is not necessary, as you don&#8217;t actually need it in your specific directive&#8217;s functionality. In that case, only the <code>$link<\/code> function could be used directly on the DDO.<\/p>\n<p>Let&#8217;s now adjust the previous simple example to use the <code>$link<\/code> function, in order to replace the content of the <code>template<\/code> attribute, on runtime and specifically, when the template element is about to be bound to data in the $scope object:<\/p>\n<p><span style=\"text-decoration: underline\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.4.8\/angular.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"app.js\"&gt;&lt;\/script&gt;\r\n&lt;body ng-app=\"myApp\"&gt;\r\n    &lt;div my-directive ng-controller=\"myController\" &gt;\r\n&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>And here is the angular&#8217;s part.<\/p>\n<p><span style=\"text-decoration: underline\"><em>app.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\r\nvar myApp = angular.module(\"myApp\", []);\r\n    myApp.directive('myDirective', function() {\r\n        var directive = {};\r\n\r\n        directive.restrict = 'A'; \r\n        template : \"<h1>Hey, I'm the directive's content, but I won't be displayed!<\/h1>\"\r\n        \r\n        directive.link = function($scope, element, attributes) {\r\n                element.html(\"This is the new content, overridden from the <code>$link<\/code> function: \" + $scope.content);\r\n                element.css(\"background-color\", \"#cccccc\");\r\n        }\r\n        \r\n\r\n        return directive;\r\n    })\r\n    myApp.controller(\"myController\", function($scope, $http) {\r\n\r\n        $scope.content = \"I'm the directive's updated content!\";\r\n        \r\n    });\r\n<\/pre>\n<p>As previously mentioned, I just went only for the attribute (<code>A<\/code>) restriction here, as line 5 shows. In line 6, we have the common content of the directive&#8217;s template, which will not actually be displayed to the end-user, as when the element is about to be bound to data in the <code>$scope<\/code> object, the <code>$link<\/code> function will be called and replace the template&#8217;s content (line 9), with the content set in the controller (line 18).<\/p>\n<p>As expected and also explained from the above, here is the output:<\/p>\n<figure id=\"attachment_10383\" aria-describedby=\"caption-attachment-10383\" style=\"width: 653px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/figure2-1.jpeg\" rel=\"attachment wp-att-10383\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/figure2-1.jpeg\" alt=\"Figure 2. App screenshot\" width=\"653\" height=\"216\" class=\"size-full wp-image-10383\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/figure2-1.jpeg 653w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/figure2-1-300x99.jpeg 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/a><figcaption id=\"caption-attachment-10383\" class=\"wp-caption-text\">Figure 2. App screenshot<\/figcaption><\/figure>\n<h2>3. Download the source code<\/h2>\n<p>This was an example of Angular.js Custom Directives.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/ng-custom-directives.zip\">ng-custom-directives.zip<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are directives in Angular.js? 1.1.1 A definition In general, directives is one of the reasons that Angular.js is famous today. They are essentially custom HTML tags and attributes that you can create &hellip;<\/p>\n","protected":false},"author":63,"featured_media":909,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-10282","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Angular.js Custom Directives Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular.js Custom Directives Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/toubou.techblog\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-27T14:15:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T14:34:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Thodoris Bais\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ThodorisBais\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thodoris Bais\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\"},\"author\":{\"name\":\"Thodoris Bais\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d\"},\"headline\":\"Angular.js Custom Directives Example\",\"datePublished\":\"2016-01-27T14:15:51+00:00\",\"dateModified\":\"2017-12-19T14:34:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\"},\"wordCount\":1233,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"articleSection\":[\"Angular.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\",\"name\":\"Angular.js Custom Directives Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"datePublished\":\"2016-01-27T14:15:51+00:00\",\"dateModified\":\"2017-12-19T14:34:35+00:00\",\"description\":\"1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Angular.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/angular-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Angular.js Custom Directives Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d\",\"name\":\"Thodoris Bais\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g\",\"caption\":\"Thodoris Bais\"},\"description\":\"Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics &amp; Telecommunications Engineering and is interested in continuous development.\",\"sameAs\":[\"http:\/\/thodorisbais.blogspot.com\",\"https:\/\/www.facebook.com\/toubou.techblog\/\",\"https:\/\/instagram.com\/thodoris.bais\/\",\"https:\/\/www.linkedin.com\/pub\/thodoris-bais\/69\/6b7\/408\",\"https:\/\/x.com\/@ThodorisBais\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/thodoris-bais\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Angular.js Custom Directives Example - Web Code Geeks - 2026","description":"1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/","og_locale":"en_US","og_type":"article","og_title":"Angular.js Custom Directives Example - Web Code Geeks - 2026","og_description":"1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/toubou.techblog\/","article_published_time":"2016-01-27T14:15:51+00:00","article_modified_time":"2017-12-19T14:34:35+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","type":"image\/jpeg"}],"author":"Thodoris Bais","twitter_card":"summary_large_image","twitter_creator":"@ThodorisBais","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Thodoris Bais","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/"},"author":{"name":"Thodoris Bais","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d"},"headline":"Angular.js Custom Directives Example","datePublished":"2016-01-27T14:15:51+00:00","dateModified":"2017-12-19T14:34:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/"},"wordCount":1233,"commentCount":1,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","articleSection":["Angular.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/","name":"Angular.js Custom Directives Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","datePublished":"2016-01-27T14:15:51+00:00","dateModified":"2017-12-19T14:34:35+00:00","description":"1. Introduction In a previous example we talked about the transclusion concept, in terms of Angular directives. 1.1 What are Directives? But, what are","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-custom-directives-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Angular.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/angular-js\/"},{"@type":"ListItem","position":4,"name":"Angular.js Custom Directives Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d","name":"Thodoris Bais","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g","caption":"Thodoris Bais"},"description":"Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics &amp; Telecommunications Engineering and is interested in continuous development.","sameAs":["http:\/\/thodorisbais.blogspot.com","https:\/\/www.facebook.com\/toubou.techblog\/","https:\/\/instagram.com\/thodoris.bais\/","https:\/\/www.linkedin.com\/pub\/thodoris-bais\/69\/6b7\/408","https:\/\/x.com\/@ThodorisBais"],"url":"https:\/\/www.webcodegeeks.com\/author\/thodoris-bais\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=10282"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10282\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/909"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=10282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=10282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=10282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}