Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the second-level Navigation Bar by Angular

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Angular how to achieve the secondary navigation bar, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The details are as follows

1. Put the menu in the database:

Put the simulation under this path:

Src/assets/json/header.json

{"siteName": "PGG Entertainment and Fitness Center", "menu": [{"id": "1", "menuName": "Home", "menuChildren": [{}], "showSubMenu": false}, {"id": "2", "menuName": "Fitness Center" "menuChildren": [{"itemId": "1", "menuChidrenItem": "living room equipment fitness"}, {"itemId": "2", "menuChidrenItem": "field sports"}, {"itemId": "3" "menuChidrenItem": "fitness knowledge"}], "showSubMenu": false}, {"id": "3", "menuName": "leisure and entertainment", "menuChildren": [{"itemId": "1", "menuChidrenItem": "health fishing"} {"itemId": "2", "menuChidrenItem": "picnic barbecue"}, {"itemId": "3", "menuChidrenItem": "Live Field"}], "showSubMenu": false}, {"id": "4" "menuName": "order Center", "menuChildren": [{"itemId": "1", "menuChidrenItem": "all orders"}, {"itemId": "2", "menuChidrenItem": "completed orders"} {"itemId": "3", "menuChidrenItem": "outstanding order"}], "showSubMenu": false}, {"id": "5", "menuName": "personal Center", "menuChildren": [{"itemId": "1" "menuChidrenItem": "user information modification"}], "showSubMenu": false}]}

Ts accepts the data and processes:

Import {Component, OnInit} from'@ angular/core';import {HttpClient, HttpClientModule} from'@ angular/common/http';@Component ({selector: 'app-header', templateUrl:'. / header.component.html', styleUrls: ['. / header.component.css']}) export class HeaderComponent implements OnInit {headData: any Constructor (private http: HttpClient) {} ngOnInit (): void {/ / http://localhost:4200/assets/json/header.json can access this.http.get ('/ assets/json/header.json') .subscribe (data = > {this.headData = data; console.log (this.headData.menu);}) } showSubMenu (item: any, index: any): void {/ / set the current submenu to display item.showSubMenu = true;} notShowSubMenu (item: any, index: any): void {/ / set the current submenu not to display item.showSubMenu = false;}}

Html display control, using ngstyle control:

{{headData.siteName}} {{item.menuName}} {{child.menuChidrenItem}}

Actual effect:

Thank you for reading this article carefully. I hope the article "how to achieve the second-level navigation bar of Angular" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 221

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report