{"id":1064,"date":"2021-11-08T07:22:16","date_gmt":"2021-11-08T07:22:16","guid":{"rendered":"https:\/\/externlabs.com\/blogs\/?p=1064"},"modified":"2023-04-04T13:08:20","modified_gmt":"2023-04-04T07:38:20","slug":"angular-components-lets-know-more-about","status":"publish","type":"post","link":"https:\/\/externlabs.com\/blogs\/angular-components-lets-know-more-about\/","title":{"rendered":"Angular Components: A Quick Guide by Developer"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Components are one of the major components when it comes to Angular. Components help to build the structure for applications. Angular components can maintain the modularity of developments and keep them reusable. They control the view, and they have the responsibility and control over HTML files which makes it controller for displayed content in the browser. First, Let\u2019s know what Angular is.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Page Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/externlabs.com\/blogs\/angular-components-lets-know-more-about\/#What_is_Angular\" title=\"What is Angular\">What is Angular<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/externlabs.com\/blogs\/angular-components-lets-know-more-about\/#Features_of_Angular\" title=\"Features of Angular\">Features of Angular<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/externlabs.com\/blogs\/angular-components-lets-know-more-about\/#What_are_Angular_Components\" title=\"What are Angular Components\">What are Angular Components<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/externlabs.com\/blogs\/angular-components-lets-know-more-about\/#Types_of_Components_in_Angular\" title=\"Types of Components in Angular\">Types of Components in Angular<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/externlabs.com\/blogs\/angular-components-lets-know-more-about\/#Metadata_of_Angular_Component\" title=\"Metadata of Angular Component\">Metadata of Angular Component<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Angular\"><\/span>What is Angular<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/about.google\/\" target=\"_blank\" rel=\"noopener\">Google Inc.<\/a> developed Angular is an open-source front-end framework. It\u2019s considered a front-end framework for innovative single-page web applications and based on the popular JavaScript, which is used widely in development and JS in the name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/externlabs.com\/blogs\/what-is-angularjs-framework\/\">Angular<\/a> is developed and has support from Google and an open community of Angular developers. This helps to keep continuous development, improvement, and new features.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Features_of_Angular\"><\/span>Features of Angular<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Angular has many great features; some of them got mentioned in the previous block, but those make developers choose Angular over others are &#8211;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Filters<\/li>\n\n\n\n<li>Services<\/li>\n\n\n\n<li>Scope<\/li>\n\n\n\n<li>Data Binding<\/li>\n\n\n\n<li>Directives<\/li>\n\n\n\n<li>Templates<\/li>\n\n\n\n<li>Routing<\/li>\n\n\n\n<li>Model View Whatever<\/li>\n\n\n\n<li>Deep-Linking<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Angular includes everything that needs to build innovative yet interactive single-page web applications. Youtube, Paypal, Netflix, and LinkedIn also have their front-end on Angular.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_Angular_Components\"><\/span>What are Angular Components<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-1024x576.png\" alt=\"angular components\" class=\"lazyload_inited wp-image-6585\" width=\"426\" height=\"239\" srcset=\"https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-1024x576.png 1024w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-300x169.png 300w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-768x432.png 768w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-380x214.png 380w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-800x450.png 800w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-1160x653.png 1160w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-760x428.png 760w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1-600x338.png 600w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2023\/04\/Angular-Component-1.png 1200w\" sizes=\"(max-width: 600px) 100vw, 426px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">A component is a directive that uses a more straightforward configuration that fits a component-based architecture, which Angular 2 is all about. Think of an element as a widget: A piece of HTML code that you can reuse in various places in your web application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Components<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span style=\"font-weight: 400;\">angular.<\/span><span style=\"font-weight: 400;\">module<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;myApp&#8217;<\/span><span style=\"font-weight: 400;\">, [])<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; &nbsp; .component(<\/span><span style=\"font-weight: 400;\">&#8216;helloWorld&#8217;<\/span><span style=\"font-weight: 400;\">, {<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span><span style=\"font-weight: 400;\">template<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8216;&lt;span&gt;Hello World!&lt;\/span&gt;&#8217;<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; &nbsp; });<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Markup<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&lt;div ng-app=&#8221;myApp&#8221;&gt;<br>\n&lt;hello-world&gt; &lt;\/hello-world&gt;<br>\n&lt;\/div&gt;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><b>Default Components<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">\u00a7 app.component.css<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">\u00a7 app.component.html<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">\u00a7 app.component.spec.ts<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">\u00a7 app.component.ts<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">\u00a7 app.module.ts<\/span><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">These are the component files that get created by default when you create an application in Angular.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Types_of_Components_in_Angular\"><\/span>Types of Components in Angular<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Now, there are two types of components in Angular:<\/span><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Parent<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Child<\/span><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The Parent Component is the one that is predefined and imported when you create the App. However, the Child component is the one that you can design according to your needs and demand.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Metadata_of_Angular_Component\"><\/span>Metadata of Angular Component<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">There is three-component configuration<\/span><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> {Component} from <\/span><span style=\"font-weight: 400;\">&#8216;@angular\/core&#8217;<\/span><span style=\"font-weight: 400;\">;<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">@Component<\/span><span style=\"font-weight: 400;\">({<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; <\/span><span style=\"font-weight: 400;\">Selector:<\/span> <span style=\"font-weight: 400;\">&#8216;app-root&#8217;<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; <\/span><span style=\"font-weight: 400;\">templateUrl:<\/span> <span style=\"font-weight: 400;\">&#8216;.\/app.component.html&#8217;<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; <\/span><span style=\"font-weight: 400;\">providers:<\/span><span style=\"font-weight: 400;\"> [<\/span><span style=\"font-weight: 400;\">&#8221;<\/span><span style=\"font-weight: 400;\">]<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">})<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">export <\/span><span style=\"font-weight: 400;\">class<\/span> <span style=\"font-weight: 400;\">AppComponent<\/span><span style=\"font-weight: 400;\"> {<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">&nbsp; title=<\/span><span style=\"font-weight: 400;\">&#8216;ExternLabs&#8217;<\/span><span style=\"font-weight: 400;\">;<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">}<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Selector: This tells angular where to create and insert the instance of this component. It is a CSS selector. The selector inserts the instance in the HTML wherever it finds the tag of the component. In this case <\/span>&lt;app-root&gt; &lt;\/app-root&gt;<\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">template URL: There are two ways to declare this.<\/span><span style=\"font-weight: 400;\"><br>\n<\/span><span style=\"font-weight: 400;\">\u2013 You can provide the module relative address of the components HTML template.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Providers: It includes an array of providers\u00ad1. They provide everything that a component might require. (provider1: It is an object that implements the interface of one of the providers. The object defines how you can obtain an injectable dependency with a DI token)<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Template: A template is a combination of regular HTML and Angular. i.e. HTML and typescript. It contains both, the &lt;html&gt; tags and {angular} scripts.<\/span><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The Angular Template Syntax augments the app logic which you have used in your HTML and also alters the data of DOM.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The template uses the property of Data binding to link and connects your app to the DOM data. It uses pipes to decide the view of the data when it is being displayed. Also, the template uses directives to control what gets displayed using the app logic.&nbsp;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">We discussed Components play a requisite role in Angular applications. Components and modules work together to secure your application and development work. We can divide them into parent and child components; They both have their roles and characteristics. For example, a template is a combination of both HTML and Agular\u2019s typescript. It defines how the content you have developed will look like. Creating a component in Angular is effortless with a single command, and Angular itself will do all others.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Components are one of the major components when it comes to Angular. Components help to build the structure for applications. Angular components can maintain the modularity of developments and keep them reusable. They control the view, and they have the responsibility and control over HTML files which makes it controller for displayed content in the&hellip;<\/p>\n","protected":false},"author":2,"featured_media":3783,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[42],"tags":[243,244,149],"class_list":["post-1064","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-angularjs-components","tag-angularjs-controller","tag-javascript-libraries"],"_links":{"self":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts\/1064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/comments?post=1064"}],"version-history":[{"count":0,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts\/1064\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/media\/3783"}],"wp:attachment":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/media?parent=1064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/categories?post=1064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/tags?post=1064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}