{"id":195,"date":"2019-10-09T09:25:23","date_gmt":"2019-10-09T09:25:23","guid":{"rendered":"https:\/\/docs.theironnetwork.org\/chankya\/?page_id=195"},"modified":"2019-10-10T06:39:30","modified_gmt":"2019-10-10T06:39:30","slug":"adding-deleting-menu-component","status":"publish","type":"page","link":"https:\/\/docs.theironnetwork.org\/chankya\/adding-deleting-menu-component\/","title":{"rendered":"Adding\/Deleting Menu &#038; Component"},"content":{"rendered":"\n<h5 id=\"adding-a-new-menu-and-component\">Adding a new menu &amp; component<\/h5>\n\n\n\n<p>We will help you in creating a new component. Follow the steps below to add a new component. We will add a test component in the template:\u200c<\/p>\n\n\n\n<p><strong>Step 1:<\/strong>\u00a0Open the\u00a0<code>src->app<\/code>\u00a0folder in the terminal or command prompt &amp; run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u200cng generate module test --routing<br><\/pre>\n\n\n\n<p>It will create a module &amp; its routing file inside the test folder.\u200c<\/p>\n\n\n\n<p><strong>Step 2:\u00a0<\/strong>Now run the following command in the same app folder like you did in the above step<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ng generate component test\/test1<br><\/pre>\n\n\n\n<p>It will create the test1 component in the test folder. After completing these two steps, when you will open the test folder, It will looks like:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"478\" height=\"142\" src=\"https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/gene1.png\" alt=\"\" class=\"wp-image-204\" srcset=\"https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/gene1.png 478w, https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/gene1-300x89.png 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/figure>\n\n\n\n<p>It contains the module, its routing file &amp; the component folder.\u200c<\/p>\n\n\n\n<p><strong>Step 3:<\/strong>&nbsp;Now open the&nbsp;<code>test-routing.module.ts<\/code>&nbsp;file to add the route of the newly created component&nbsp;<code>test1<\/code>. You need to import the component and then define the path of the component. Like given in the example below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { NgModule } from '@angular\/core';<br>import { Routes, RouterModule } from '@angular\/router';<br>import { Test1Component } from '.\/test1\/test1.component';\/\/ Import the component<br><br>const routes: Routes = [<br>     \/\/ Define the path of the component test1<br>     {<br>         path : '',<br>         component : Test1Component<br>     }<br> ];<br> @NgModule({<br>     imports: [RouterModule.forChild(routes)],<br>     exports: [RouterModule]<br> })<br> export class TestRoutingModule { }<\/pre>\n\n\n\n<p><strong>Step 4:\u00a0<\/strong>Open the\u00a0<code>src->app->app-routing.module.ts<\/code>\u00a0file and add the route of the test module in the children array. See the code below for the reference:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">children: [<br>   \u2026<br>   \/\/ Newly added route of the test module<br>   { path: 'test', loadChildren : () => import('.\/test\/test.module').then(m=> m.TestModule)}<br>]<\/pre>\n\n\n\n<p><strong>Step 5:\u00a0<\/strong>Now add this component in the sidebar menu. Open the\u00a0<code>src->app->core->menu->menu-items->menu-items.ts<\/code>\u00a0file and add the component in the\u00a0<code>MENUITEMS<\/code>array. Like we have added in the below example.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const MENUITEMS = [<br>   \u2026<br>    \/\/ Added Component<br>    {<br>       state: 'test',<br>       name: 'Test',<br>       type: 'link',<br>       icon: 'icon-notebook icons',<br>       label: 'New'<br>    }<br> ];<\/pre>\n\n\n\n<p><strong>Step 6:\u00a0<\/strong>Now you need to add the title of the component, for that you need to import the\u00a0<code>src->app->core->page-title->page-title.service.ts<\/code>\u00a0file in the\u00a0<code>src->app->test->test1->test1.component.ts<\/code>\u00a0file, call them in the constructor and call the\u00a0<code>setTitle<\/code>method in the\u00a0<code>ngOnInit<\/code>\u00a0function and pass the string you want as title of the component.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { Component, OnInit } from '@angular\/core';<br><br>\/\/ Add the import structure<br>import { PageTitleService } from '..\/..\/core\/page-title\/page-title.service';<br> .....<br>export class Test1Component implements OnInit {<br>    \/\/ Call them in constructor<br>    constructor(private pageTitle : PageTitleService) { }<br>    ngOnInit() {<br>       \/\/ Call the method and pass the string you want as title of the component<br>       this.pageTitle.setTitle(\"Test 1\");<br>    }<br>}<\/pre>\n\n\n\n<p>Now you have completed all the steps of adding the component in the template &amp; the sidebar menu. Save the file and open the browser, you will see your newly added component in the sidebar. Have a look at the screenshot below to check how your component is added in the template:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"505\" src=\"https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/Screenshot-from-2019-10-09-15-49-26-1024x505.png\" alt=\"\" class=\"wp-image-208\" srcset=\"https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/Screenshot-from-2019-10-09-15-49-26-1024x505.png 1024w, https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/Screenshot-from-2019-10-09-15-49-26-300x148.png 300w, https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/Screenshot-from-2019-10-09-15-49-26-768x379.png 768w, https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/Screenshot-from-2019-10-09-15-49-26.png 1320w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h5 id=\"deleting-a-menu-and-component-from-the-menu-list\">Deleting a menu &amp; component from the menu list<\/h5>\n\n\n\n<p>We will help you in deleting a menu &amp; its component from the menu list by listing down the steps needed to delete. Please follow the steps described below, We will take an example by deleting the test1 component &amp; TEST menu from the menu list which we have created in the above part:\u200c<\/p>\n\n\n\n<p><strong>Step 1:<\/strong>\u00a0Firstly, open the\u00a0<code>src->app->test->test.module.ts<\/code>\u00a0file and remove the\u00a0<code>test1<\/code>\u00a0component\u00a0<code>import statement<\/code>\u00a0&amp; its declaration from the\u00a0<code>declarations<\/code>\u00a0array in the file. Like we have removed the commented lines from the given code example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { NgModule } from '@angular\/core';<br>import { CommonModule } from '@angular\/common';<br>import { TestRoutingModule } from '.\/test-routing.module';<br>\/\/import { Test1Component } from '.\/test1\/test1.component'; \/\/ delete this import statement<br><br> @NgModule({<br>    declarations: [<br>       \/\/Test1Component \/\/ delete this declaration<br>    ],<br>    imports: [<br>       CommonModule,<br>       TestRoutingModule<br>     ]<br> })<br> export class TestModule { }<\/pre>\n\n\n\n<p>Step 2: Now open the src->app->test->test-routing.module.ts file and remove the import statement of test1 component &amp; its route from the routes array. Like we have removed the commented lines from the given code example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { NgModule } from '@angular\/core';<br>import { Routes, RouterModule } from '@angular\/router';<br>\/\/import { Test1Component } from '.\/test1\/test1.component';\/\/ delete this import statement<br><br>const routes: Routes = [<br>   \/\/ delete this route<br>   \/\/ {<br>     \/\/  path : '',<br>     \/\/  component : Test1Component<br>    \/\/ }<br> ];<br> @NgModule({<br>   imports: [RouterModule.forChild(routes)],<br>   exports: [RouterModule]<br> })<br> export class TestRoutingModule { }<\/pre>\n\n\n\n<p><strong>Step 3:\u00a0<\/strong>Now delete the\u00a0<code>test1<\/code>\u00a0component folder manually from the\u00a0<code>src->app->test<\/code>\u00a0folder.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"478\" height=\"142\" src=\"https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/gene2.png\" alt=\"\" class=\"wp-image-205\" srcset=\"https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/gene2.png 478w, https:\/\/docs.theironnetwork.org\/chankya\/wp-content\/uploads\/sites\/8\/2019\/10\/gene2-300x89.png 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/figure>\n\n\n\n<p><strong>Step 4:\u00a0<\/strong>Open the\u00a0<code>src->app->core->menu->menu-items->menu-items.ts<\/code>\u00a0file and remove the component from the\u00a0<code>MENUITEMS<\/code>\u00a0array. Like we have removed the commented lines from the given code example.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const MENUITEMS = [<br>   \u2026<br>   \/\/ deleted\/removed Component<br>   \/\/{<br>     \/\/  state: 'test',<br>     \/\/  name: 'Test',<br>     \/\/  type: 'link',<br>     \/\/  icon: 'icon-notebook icons',<br>     \/\/  label: 'New'<br>   \/\/ }<br>];<br><\/pre>\n\n\n\n<p>That\u2019s it, now you have completed all the steps to delete a menu from the menu list and its component from the app. Save the file and open the browser, now you will see that your template does not contains your deleted component anymore.<br><\/p>\n<div class=\"pld-like-dislike-wrap pld-template-1\">\n    <div class=\"pld-like-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-like-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"195\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-ip-check=\"0\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-up\"><\/i>\n                    <\/a>\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-dislike-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"195\" data-trigger-type=\"dislike\" data-ip-check=\"0\" data-restriction=\"cookie\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-down\"><\/i>\n                    <\/a>\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\n<\/div><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Adding a new menu &amp; component We will help you in creating a new component. Follow the steps below to add a new component. We will add a test component in the template:\u200c Step 1:\u00a0Open the\u00a0src->app\u00a0folder in the terminal or command prompt &amp; run the following command: \u200cng generate module test &#8211;routing It will create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/pages\/195"}],"collection":[{"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":6,"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/pages\/195\/revisions"}],"predecessor-version":[{"id":209,"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/pages\/195\/revisions\/209"}],"wp:attachment":[{"href":"https:\/\/docs.theironnetwork.org\/chankya\/wp-json\/wp\/v2\/media?parent=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}