diff --git a/docs/en/UI/Angular/Modifying-the-Menu.md b/docs/en/UI/Angular/Modifying-the-Menu.md index 76298e1674..f728fb2f9a 100644 --- a/docs/en/UI/Angular/Modifying-the-Menu.md +++ b/docs/en/UI/Angular/Modifying-the-Menu.md @@ -3,9 +3,6 @@ The menu is inside the `ApplicationLayoutComponent` in the @abp/ng.theme.basic package. There are several methods for modifying the menu elements. This document covers these methods. If you would like to replace the menu completely, please refer to [Component Replacement documentation](./Component-Replacement.md) and learn how to replace a layout. - - - ## How to Add a Logo The `logoUrl` property in the environment variables is the url of the logo. @@ -215,51 +212,63 @@ After the operations above, the new menu looks like below: ## How to Add an Element to Right Part of the Menu -The right part elements are stored in the `LayoutState` that is in the @abp/ng.theme.basic package. - -The `dispatchAddNavigationElement` method of the `LayoutStateService` adds an element to the right part of the menu. - -You can insert an element by adding your template to `app.component` and calling the `dispatchAddNavigationElement` method: +You can add elements to the right part of the menu by calling the `addItems` method of `NavItemsService`. It is a singleton service, i.e. provided in root, so you can inject and use it immediately. ```js -import { Layout, LayoutStateService } from '@abp/ng.theme.basic'; // added this line +import { NavItemsService } from '@abp/ng.theme.shared'; +import { Component } from '@angular/core'; @Component({ - selector: 'app-root', template: ` - - - + `, }) -export class AppComponent { - // Added ViewChild - @ViewChild('search', { static: false, read: TemplateRef }) searchElementRef: TemplateRef; +export class MySearchInputComponent {} - constructor(private layout: LayoutStateService) {} // injected LayoutStateService - // Added ngAfterViewInit - ngAfterViewInit() { - const newElement = { - name: 'Search', - element: this.searchElementRef, - order: 1, - } as Layout.NavigationElement; - - this.layout.dispatchAddNavigationElement(newElement); +@Component(/* component metadata */) +export class AppComponent { + constructor(private navItems: NavItemsService) { + navItems.addItems([ + { + id: 'MySearchInput', + order: 1, + component: MySearchInputComponent, + }, + { + id: 'SignOutIcon', + html: '', + action: () => console.log('Clicked the sign out icon'), + order: 102, // puts as last element + }, + ]); } } ``` -This inserts a search input to the menu. The final UI looks like below: +This inserts a search input and a sign out icon to the menu. The final UI looks like below: ![navigation-menu-search-input](./images/navigation-menu-search-input.png) -## How to Remove an Element From Right Part of the Menu +## How to Patch or Remove an Right Part Element + +The `patchItem` method of `NavItemsService` finds an element by its `id` property and replaces its configuration with the new configuration passed as the second parameter. Similarly, `removeItem` method finds an element and removes it. + +```js +export class AppComponent { + constructor(private navItems: NavItemsService) { + navItems.patchItem(eThemeBasicComponents.Languages, { + requiredPolicy: 'new policy here', + order: 1, + }); + + navItems.removeItem(eThemeBasicComponents.CurrentUser); + } +} +``` -TODO +* Patched the languages dropdown element with new `requiredPolicy` and new `order`. +* Removed the current user dropdown element. ## What's Next diff --git a/docs/en/UI/Angular/images/navigation-menu-search-input.png b/docs/en/UI/Angular/images/navigation-menu-search-input.png index ebdc05e3e0..e93b7927d1 100644 Binary files a/docs/en/UI/Angular/images/navigation-menu-search-input.png and b/docs/en/UI/Angular/images/navigation-menu-search-input.png differ