{"id":21022,"date":"2018-10-04T16:15:02","date_gmt":"2018-10-04T13:15:02","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=21022"},"modified":"2018-10-03T16:45:28","modified_gmt":"2018-10-03T13:45:28","slug":"angularjs-components-library-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/","title":{"rendered":"AngularJS Components Library Example"},"content":{"rendered":"<p>In this article, we will take a look at developing a custom AngularJS Component. Then, we will learn to package it as a library so that we can reuse it across different projects. Firstly, we will start by getting familiar with the underlying concepts and their implementation leading up to writing our own Component library. Finally, we will consume the same in a sample component based application. So, let&#8217;s get started.<\/p>\n<p>As part of this effort to explore components we will build a simple user registration component. We will then package the same as a library so that we can reuse this component across applications. The component will show a simple UI prompting for a username and password on a registration page. The component includes a password strength checker which will show compliance with a set of rules for a secure password.<br \/>\n[ulp id=&#8217;LXJcMJZXSsqGXYW8&#8242;]<\/p>\n<div class=\"toc\">\n<h3>Table of Contents<\/h3>\n<dl>\n<dt><a href=\"#Technology\">1. Tools &amp; Technologies<\/a><\/dt>\n<dt><a href=\"#Project\">2. Project Structure<\/a><\/dt>\n<dt><a href=\"#Intro\">3. Introduction to AngularJS Components<\/a><\/dt>\n<dt><a href=\"#Create\">4. Creating a Component<\/a><\/dt>\n<dt><a href=\"#Publishing\">5. Publishing the Library<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#OpenSource\">5.1 Publish with Public Access<\/a><\/dt>\n<dt><a href=\"#ClosedSource\">5.2 Publish with Restricted Access<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#Consuming\">6. Consuming our Library<\/a><\/dt>\n<dt><a href=\"#Download\">7. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"Technology\"><\/a>1. Tools &amp; Technologies<\/h2>\n<p>We will build a component and package it as a library as we learn about the topic. I have chosen the below set of tools and will use the following technologies as we work in this post. Although, feel free to use a different toolset as per your preference.<\/p>\n<ol>\n<li><a href=\"https:\/\/nodejs.org\/en\/\" target=\"_blank\" rel=\"noopener\">NodeJS v6.3.0<\/a><\/li>\n<li><a href=\"https:\/\/code.angularjs.org\/\" target=\"_blank\" rel=\"noopener\">AngularJS v1.7.4<\/a><\/li>\n<li><a href=\"https:\/\/code.visualstudio.com\/Download\" target=\"_blank\" rel=\"noopener\">Visual Studio Code IDE<\/a><\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/http-server\" target=\"_blank\" rel=\"noopener\">http-server v0.11.1<\/a><\/li>\n<\/ol>\n<h2><a name=\"Project\"><\/a>2. Project Structure<\/h2>\n<p>There are two separate folders as you can see in the below screen grab. One will host our custom component library and the other will host a sample application which will consume the component.<\/p>\n<figure id=\"attachment_22820\" aria-describedby=\"caption-attachment-22820\" style=\"width: 243px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/09\/ProjectFolderStructure.jpg\"><img decoding=\"async\" class=\"wp-image-22820 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/09\/ProjectFolderStructure.jpg\" alt=\"AngularJS Components Library - Project Folder Structure\" width=\"243\" height=\"410\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/09\/ProjectFolderStructure.jpg 243w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/09\/ProjectFolderStructure-178x300.jpg 178w\" sizes=\"(max-width: 243px) 100vw, 243px\" \/><\/a><figcaption id=\"caption-attachment-22820\" class=\"wp-caption-text\">Project Folder Structure<\/figcaption><\/figure>\n<h2><a name=\"Intro\"><\/a>3. Introduction to AngularJS Components<\/h2>\n<p>Components were introduced with version 1.5 of AngularJS. They can be thought of as directives with templates. Apart from this they allow us to structure our app as a Component based one. Unlike directives which are applied to existing <code>DOM<\/code> elements to impart additional behavior. A component has its own <code>HTML<\/code> called its template. Let us take a look at how we define a Component.<br \/>\nA component resides in a <code>js<\/code> file with code that looks like below:<\/p>\n<pre class=\"brush: js;\">angular.\r\n  module('moduleName').\r\n  component('componentName', {\r\n    template: 'Hello, {{$ctrl.user}}!',\r\n    controller: function GreetUserController() {\r\n      this.user = 'world';\r\n    }\r\n  });\r\n<\/pre>\n<p>We call the component method of an AngularJS Module and pass the name of the component as the first argument and an object called <code>CDO<\/code> or Component Description Object, which describes the component as the second argument. With templates for a Component we can either specify it inline by setting the value of template to a <code>HTML<\/code> snippet. Or we can also pass the <code>URL<\/code> of the <code>HTML<\/code> file containing the template by setting the <code>templateUrl<\/code> property.<\/p>\n<h2><a name=\"Create\"><\/a>4. Creating a Component<\/h2>\n<p>We will create a component which encapsulates functionality to render a user registration view. This component will also check for password strength and provide feedback to the user. We will wrap this piece into a library of its own so that we can easily share it among different applications with just a few steps.<\/p>\n<p>Add the following files in a folder named similar after the component, i.e. <code>user-registration-component<\/code>.<\/p>\n<ul>\n<li>package.json<\/li>\n<li>user-registration.component.js<\/li>\n<li>user-registration.template.html<\/li>\n<li>user-registration.module.js<\/li>\n<li>user-registration.style.css<\/li>\n<\/ul>\n<p>The <code>package.json<\/code> file is needed to list the dependencies of our component library, version and name among other things. The content of the file are as below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush: js;\">{\r\n    \"name\": \"user-registration-component\",\r\n    \"version\": \"1.0.0\",\r\n    \"description\": \"WCG -- AngularJS Component Library\",\r\n    \"scripts\": {\r\n        \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\",\r\n        \"start\": \"http-server .\/ -a localhost -p 8090 -c-1\"\r\n    },\r\n    \"keywords\": [\r\n        \"AngularJS\",\r\n        \"Component\",\r\n        \"Library\",\r\n        \"User\",\r\n        \"Registration\"\r\n    ],\r\n    \"author\": \"Siddharth@WCG\",\r\n    \"license\": \"ISC\",\r\n    \"dependencies\": {\r\n        \"angular\": \"^1.7.4\",\r\n        \"bootstrap\": \"3.3.x\"\r\n    }\r\n}\r\n<\/pre>\n<p>Now we create a file where we declare our module. This module will host our component as we will see later. The contents of this file <code>user-registration.module.js<\/code> is as below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>user-registration.module.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">'use strict';\r\n\r\nangular.module('userRegistrationModule', []);\r\n<\/pre>\n<p>Moving on now we create our <code>Component<\/code> itself. The file, <code>user-registration.component.js<\/code>, has our component and it looks as below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>user-registration.component.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">'use strict';\r\n\r\nangular.module('userRegistrationModule').\r\ncomponent('userRegistration',\r\n{\r\n    templateUrl: '\/node_modules\/user-registration-component\/user-registration.template.html',\r\n    controller: function () {\r\n        var self = this;\r\n        self.pwd = \"\";\r\n        self.strength = '100%';\r\n        self.score = 0;\r\n        self.checkUpperCase = function () {\r\n            for (var c = 0; c &lt; self.pwd.length; c++) {\r\n                if (self.pwd.charCodeAt() &gt;= 65 &amp;&amp; self.pwd.charCodeAt() &lt;= 91) {\r\n                    return 1;\r\n                }\r\n            }\r\n            return 0;\r\n        };\r\n\r\n        self.checkEmpty = function () {\r\n            var p = self.pwd || \"\";\r\n            if (p.length &gt; 0) {\r\n                return 1;\r\n            }\r\n            return 0;\r\n        };\r\n        self.checkDigit = function () {\r\n            var p = self.pwd || \"\";\r\n            var digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];\r\n            var result = 0;\r\n            digits.forEach(function(item) {\r\n                if (p.includes(item)) {\r\n                    result = 1;\r\n                    return;\r\n                }\r\n            });\r\n            return (result === 0 ? 0: 1);\r\n        };\r\n        self.checkLength = function () {\r\n            var p = self.pwd || \"\";\r\n            if (p.length &gt;= 8) {\r\n               return 1;\r\n            }\r\n            return 0;\r\n        };\r\n        self.checkSpecialChar = function () {\r\n            var specChars = ['*', '@', '_', '.'];\r\n            var p = self.pwd || \"\";\r\n            var result = 0;\r\n            specChars.forEach(function(item) {\r\n                if (p.includes(item)) {\r\n                    result = 1;\r\n                    return;\r\n                }\r\n            });\r\n            return (result === 0 ? 0: 1);\r\n        };\r\n        self.rules = [{\r\n            ruleFn: self.checkEmpty,\r\n            score: 0\r\n        }, {\r\n            ruleFn: self.checkDigit,\r\n            score: 0\r\n        }, {\r\n            ruleFn: self.checkUpperCase,\r\n            score: 0\r\n        }, {\r\n            ruleFn: self.checkSpecialChar,\r\n            score: 0\r\n        }, {\r\n            ruleFn: self.checkLength,\r\n            score: 0\r\n        }];\r\n\r\n        self.checkStrength = function () {\r\n            self.score = 0;\r\n            var runningTotal = 0;\r\n            self.rules.forEach(function (item) {\r\n                item.score = item.ruleFn();\r\n                runningTotal += item.score;\r\n                self.strength = (100 - ((runningTotal \/ self.rules.length) * 100)) + '%';\r\n             }, self);\r\n        };\r\n    }\r\n});\r\n<\/pre>\n<p>What we are doing here is declaring a component with template residing in a file called <code>user-registration.template.html<\/code> and a controller for this component. The template is described below and as for the controller it has code to check the strength of the password based on a set of rules. The rules are stored in an array of objects with each object having a function which evaluates the password and returns a score. The score is zero if the password fails the check otherwise it has a value of 1. We use the score from each function to evaluate the strength of the password and show it using a color scheme, with Red representing Weak password and Green representing a Strong password.<br \/>\nThe process is triggered on the change event of the password field in the template.<\/p>\n<p>The template of our component looks as below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>user-registration.template.html<\/em><\/span><\/p>\n<pre class=\"brush: html;\">&lt;form&gt;\r\n    &lt;div class=\"form-group\"&gt;\r\n        &lt;label class=\"sr-only\" for=\"inputUsername\"&gt;Username&lt;\/label&gt;\r\n        &lt;input class=\"form-control\" type=\"text\" placeholder=\"Username\" \/&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=\"row\"&gt;\r\n        &lt;div class=\"col-xs-12 col-sm-6 col-md-6\"&gt;\r\n            &lt;div class=\"form-group\"&gt;\r\n                &lt;input class=\"form-control\" new-password type=\"password\"\r\n ng-model=\"$ctrl.pwd\" ng-change=\"$ctrl.checkStrength()\" id=\"inputPassword\" \r\n placeholder=\"Password\" \/&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=\"col-xs-12 col-sm-6 col-md-6\"&gt;\r\n            &lt;div class=\"form-group\"&gt;\r\n                &lt;input class=\"form-control\" new-password type=\"password\"\r\n id=\"inputConfirmPassword\" placeholder=\"Confirm Password\" \/&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=\"row\"&gt;\r\n        &lt;div class=\"col-xs-12 col-sm-6 col-md-6\"&gt;\r\n            &lt;label&gt;Password Strength&lt;\/label&gt;\r\n            &lt;div class=\"gradient\"&gt;\r\n                &lt;div ng-style=\"{ 'width': $ctrl.strength }\"&gt;&lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div&gt;\r\n        &lt;ul&gt;\r\n            &lt;li&gt;Password cannot be empty&lt;\/li&gt;\r\n            &lt;li&gt;Must contain atleast one Uppercase character&lt;\/li&gt;\r\n            &lt;li&gt;Must contain atleast one number&lt;\/li&gt;\r\n            &lt;li&gt;Must contain one of these characters * @ _ .&lt;\/li&gt;\r\n            &lt;li&gt;Must be of 8 characters in length &lt;\/li&gt;\r\n        &lt;\/ul&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=\"row\"&gt;\r\n        &lt;div class=\"col-xs-12 col-sm-6 col-md-6\"&gt;\r\n            &lt;div class=\"form-group\"&gt;\r\n                &lt;button type=\"button\" class=\"form-control btn btn-success\"&gt;\r\n                    Register\r\n                &lt;\/button&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<h2><a name=\"Publishing\"><\/a>5. Publishing the Library<\/h2>\n<p>To reuse our component in other applications we need to publish it. We will use <code>npm<\/code> to achieve the same. We have a couple of options, either we publish our component as public or as a scoped package. The difference in the two being who is able to access the component. If we publish our component as public then everyone can access it. Otherwise we can go for scoped packages which limits the access to our component to our own organization. Let us look at the steps required to publish using both options. Before we begin using either option, we need to have an account with <a href=\"https:\/\/www.npmjs.com\/signup\" target=\"_blank\" rel=\"noopener\">npmjs.org<\/a> albeit one requires a paid account to publish scoped packages.<\/p>\n<h3><a name=\"OpenSource\"><\/a>5.1 Publish with Public Access<\/h3>\n<p>To publish our component as a library with public access we need to follow the below steps<br \/>\nFirst, navigate to the directory containing the component and related artifacts that we want to publish.<\/p>\n<pre class=\"brush: bash;\">&gt;cd Component Library\/user-registration-component\r\n<\/pre>\n<p>Then we need to login with npmjs.org credentials by using the following command.<\/p>\n<pre class=\"brush: bash;\">&gt;npm adduser\r\n<\/pre>\n<p>Afterwards we run the following command<\/p>\n<pre class=\"brush: bash;\">&gt;npm publish\r\n<\/pre>\n<p>This will publish our component library to npm and you can verify the same by visiting <code>http:\/\/npmjs.org<\/code> and searching by the name you gave your library.<br \/>\nTo publish an updated version we need to update the version of our component in the package.json file in the directory of the component and follow the above steps again.<\/p>\n<h3><a name=\"ClosedSource\"><\/a>5.2 Publish with Restricted Access<\/h3>\n<p>To publish our component with private access we need to perform the below steps<br \/>\nNavigate to our component library directory<\/p>\n<pre class=\"brush: bash;\">&gt;cd Component Library\/user-registration-component\r\n<\/pre>\n<p>Login with the npmjs.org account:<\/p>\n<pre class=\"brush: bash;\">&gt;npm adduser\r\n<\/pre>\n<p>Then run the below command:<\/p>\n<pre class=\"brush: bash;\">&gt;npm publish --access restricted\r\n<\/pre>\n<p>This should publish our component library with private access. We will take a look in the next section how to consume the same in another project.<\/p>\n<h2><a name=\"Consuming\"><\/a>6. Consuming our Library<\/h2>\n<p>Now that we are done publishing our component library let us take a look at how we can consume the same in an application. All the action would now be in the folder Demo Application. The Demo Application is setup as a simple AngularJS template with just a root app module and an <code>index.html<\/code> page. Now to pull down our published library and add it to this project we need to run the following command at the root of the project.<\/p>\n<pre class=\"brush:bash;\">&gt;npm install user-registration-module --save\r\n<\/pre>\n<p>This should pull down the latest version of our library and save it as a dependency in the <code>package.json<\/code> file of the project. The package.json file of our Demo Application should look like below:<\/p>\n<figure id=\"attachment_22870\" aria-describedby=\"caption-attachment-22870\" style=\"width: 774px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/PackageJSONFileDemo.jpg\"><img decoding=\"async\" class=\"wp-image-22870 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/PackageJSONFileDemo.jpg\" alt=\"AngularJS Components Library - Package.json File\" width=\"774\" height=\"410\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/PackageJSONFileDemo.jpg 774w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/PackageJSONFileDemo-300x160.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/PackageJSONFileDemo-768x407.jpg 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/a><figcaption id=\"caption-attachment-22870\" class=\"wp-caption-text\">Package.json File<\/figcaption><\/figure>\n<p>Next we need to add the following script tags to our <code>index.html<\/code> page.<\/p>\n<pre class=\"brush: xml;\">&lt;script src=\"node_modules\/user-registration-component\/user-registration.module.js\"&gt;&lt;\/script&gt;\r\n&lt;scriptsrc=\"node_modules\/user-registration-component\/user-registration.component.js\"&gt;&lt;\/script&gt;\r\n<\/pre>\n<p>This will pull down our library for use. We need to add the <code>userRegistrationModule<\/code> as a dependency of the root module of our demo application in the <code>app.module.js<\/code> file as below:<\/p>\n<pre class=\"brush: js;\">'use strict';\r\n\r\nangular.module('userRegistrationDemo', ['userRegistrationModule']);\r\n\r\n<\/pre>\n<p>All that we need to do now is add the following tag to our HTML file <code>index.html<\/code>.<\/p>\n<pre class=\"brush: html;\">&lt;user-registration&gt;&lt;\/user-registration&gt;\r\n<\/pre>\n<p>The contents of the <code>index.html<\/code> file should look like below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush: xml;\">&lt;!doctype html&gt;\r\n&lt;html lang=\"en\" ng-app=\"userRegistrationDemo\"&gt;\r\n\r\n    &lt;head&gt;\r\n        &lt;meta name=\"viewport\"\r\n        content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\"&gt;\r\n        &lt;meta charset=\"utf-8\"&gt;\r\n        &lt;title&gt;WCG -- Angularjs Component Library Demonstration&lt;\/title&gt;\r\n        &lt;link rel=\"stylesheet\" href=\"node_modules\/bootstrap\/dist\/css\/bootstrap.css\" \/&gt;\r\n        &lt;link rel=\"stylesheet\" href=\"app.css\" \/&gt;\r\n        &lt;script src=\"node_modules\/angular\/angular.js\"&gt;&lt;\/script&gt;\r\n        &lt;script src=\"app.module.js\"&gt;&lt;\/script&gt;\r\n        &lt;script src=\"node_modules\/user-registration-component\/user-registration.module.js\"&gt;\r\n        &lt;\/script&gt;\r\n        &lt;script src=\"node_modules\/user-registration-component\/user-registration.component.js\"&gt;\r\n        &lt;\/script&gt;\r\n    &lt;\/head&gt;\r\n\r\n    &lt;body&gt;\r\n        &lt;div class=\"container\"&gt;\r\n            &lt;h3&gt;WCG -- Angularjs Component Library Demonstration&lt;\/h3&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=\"container\"&gt;\r\n            &lt;div class=\"row\"&gt;\r\n                &lt;div class=\"col-md-12\"&gt;\r\n                    &lt;user-registration&gt;&lt;\/user-registration&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>To look at the results we will run the application using the following command<\/p>\n<pre class=\"brush: bash;\">&gt;npm start\r\n<\/pre>\n<p>Then we should navigate to the following URL in the browser <code>http:\/\/localhost:8090<\/code>. The browser would display the index page as below<\/p>\n<figure id=\"attachment_22866\" aria-describedby=\"caption-attachment-22866\" style=\"width: 756px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPageWCG.jpg\"><img decoding=\"async\" class=\"wp-image-22866 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPageWCG.jpg\" alt=\"AngularJS Components Library - Landing Page\" width=\"756\" height=\"403\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPageWCG.jpg 756w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPageWCG-300x160.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPageWCG-620x330.jpg 620w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/a><figcaption id=\"caption-attachment-22866\" class=\"wp-caption-text\">Landing Page<\/figcaption><\/figure>\n<p>As soon as you start typing in the password field you would see the strength checker provide feedback on the password. You should see something like below:<\/p>\n<figure id=\"attachment_22868\" aria-describedby=\"caption-attachment-22868\" style=\"width: 757px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPagePwdStrength.jpg\"><img decoding=\"async\" class=\"wp-image-22868 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPagePwdStrength.jpg\" alt=\"AngularJS Components Library - Landing Page Activity\" width=\"757\" height=\"418\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPagePwdStrength.jpg 757w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/10\/LandingPagePwdStrength-300x166.jpg 300w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/a><figcaption id=\"caption-attachment-22868\" class=\"wp-caption-text\">Landing Page Activity<\/figcaption><\/figure>\n<h2><a name=\"Download\"><\/a>7. Download the Source Code<\/h2>\n<p>This wraps up how to create and publish an AngularJS Component Library.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:<a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2018\/09\/WCG-AngularJS-Component-Library.zip\"><strong> AngularJS Component Library<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will take a look at developing a custom AngularJS Component. Then, we will learn to package it as a library so that we can reuse it across different projects. Firstly, we will start by getting familiar with the underlying concepts and their implementation leading up to writing our own Component library. &hellip;<\/p>\n","protected":false},"author":213,"featured_media":909,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[266],"class_list":["post-21022","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-js","tag-angularjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>AngularJS Components Library Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn more about AngularJS? Then check out our detailed example on AngularJS Components Library! You can also download our FREE AngularJS Programming Cookbook!\" \/>\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\/angularjs-components-library-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AngularJS Components Library Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about AngularJS? Then check out our detailed example on AngularJS Components Library! You can also download our FREE AngularJS Programming Cookbook!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-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:published_time\" content=\"2018-10-04T13:15:02+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=\"Siddharth Seth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Seth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 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\/angularjs-components-library-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/\"},\"author\":{\"name\":\"Siddharth Seth\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/9c939eb4c915443c7e493c813d979592\"},\"headline\":\"AngularJS Components Library Example\",\"datePublished\":\"2018-10-04T13:15:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/\"},\"wordCount\":1351,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"keywords\":[\"angularjs\"],\"articleSection\":[\"Angular.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/\",\"name\":\"AngularJS Components Library Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"datePublished\":\"2018-10-04T13:15:02+00:00\",\"description\":\"Interested to learn more about AngularJS? Then check out our detailed example on AngularJS Components Library! You can also download our FREE AngularJS Programming Cookbook!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-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\/angularjs-components-library-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\":\"AngularJS Components Library 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\/9c939eb4c915443c7e493c813d979592\",\"name\":\"Siddharth Seth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"caption\":\"Siddharth Seth\"},\"description\":\"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.\",\"sameAs\":[\"https:\/\/www.webcodegeeks.com\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/siddharth-seth\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AngularJS Components Library Example - Web Code Geeks - 2026","description":"Interested to learn more about AngularJS? Then check out our detailed example on AngularJS Components Library! You can also download our FREE AngularJS Programming Cookbook!","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\/angularjs-components-library-example\/","og_locale":"en_US","og_type":"article","og_title":"AngularJS Components Library Example - Web Code Geeks - 2026","og_description":"Interested to learn more about AngularJS? Then check out our detailed example on AngularJS Components Library! You can also download our FREE AngularJS Programming Cookbook!","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2018-10-04T13:15:02+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":"Siddharth Seth","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Siddharth Seth","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/"},"author":{"name":"Siddharth Seth","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/9c939eb4c915443c7e493c813d979592"},"headline":"AngularJS Components Library Example","datePublished":"2018-10-04T13:15:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/"},"wordCount":1351,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","keywords":["angularjs"],"articleSection":["Angular.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/","name":"AngularJS Components Library Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","datePublished":"2018-10-04T13:15:02+00:00","description":"Interested to learn more about AngularJS? Then check out our detailed example on AngularJS Components Library! You can also download our FREE AngularJS Programming Cookbook!","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angularjs-components-library-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\/angularjs-components-library-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":"AngularJS Components Library 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\/9c939eb4c915443c7e493c813d979592","name":"Siddharth Seth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","caption":"Siddharth Seth"},"description":"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.","sameAs":["https:\/\/www.webcodegeeks.com"],"url":"https:\/\/www.webcodegeeks.com\/author\/siddharth-seth\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/21022","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\/213"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=21022"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/21022\/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=21022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=21022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=21022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}