简体   繁体   English

angular中如何根据用户点击显示数据

[英]How to display the data based on the user click in angular

I have added tool bar and side nav bar using angular material in app.component.html.我在 app.component.html 中使用 angular 材料添加了工具栏和侧导航栏。

app.component.html app.component.html

<div>
   <mat-sidenav-container class="main-container">
     <mat-sidenav #sideBarRef opened mode="side" [(opened)]='isSideBarOpen'>
     <mat-nav-list>
       <a mat-list-item href="#"> Home </a>        
       <a mat-list-item href="#"> Project Updates </a>        
       <a mat-list-item href="#"> General Updates </a>
       <a mat-list-item href="#"> Help </a>
     </mat-nav-list>
   </mat-sidenav>
   <mat-sidenav-content>
     <mat-toolbar color="primary">
        <button (click)='sideBarRef.toggle()'><mat-icon>menu</mat-icon></button>
           My Application
     </mat-toolbar>
  </mat-sidenav-content>
</mat-sidenav-container>
</div>

In the UI it looks like below.在 UI 中,它如下所示。 在此处输入图像描述

As of now I have only one component in my app ie application component.到目前为止,我的应用程序中只有一个组件,即应用程序组件。 Now I want to develop different components for each of the buttons which are on left side in the home page.现在我想为主页左侧的每个按钮开发不同的组件。 When user clicks on any button I want to show the corresponding html template right to those buttons.当用户单击任何按钮时,我想在这些按钮右侧显示相应的 html 模板。

How can I implement this?我该如何实施? I appreciate your help.我感谢您的帮助。

There is multiple ways to implement this, depending on your app architecture and what's exactly your use case.有多种方法可以实现这一点,具体取决于您的应用架构和您的用例。

  • If when user click on A it changes both data and display, like an admin interface allowing to manage users, groups, application on 3 side buttons, use a in your main comp, create one route/comp per display and router the user using router-link for each button.如果当用户单击 A 时,它会同时更改数据和显示,例如管理界面允许在 3 个侧边按钮上管理用户、组、应用程序,在主组件中使用 a,为每个显示创建一个路由/组件,并使用路由器路由用户- 每个按钮的链接。
  • If the display stay the same, but the button simply change the underlying data, use a smart component to built your view, 1 presentation component to build your left panel, Observable of your data filtered by which button is clicked using input/output and 1 presentation component to make the main display using the data sent by the smart comp.如果显示保持不变,但按钮只是更改基础数据,请使用智能组件来构建视图,1 个演示组件来构建左侧面板,可观察的数据由使用输入/输出单击哪个按钮过滤,以及 1演示组件使用智能组件发送的数据进行主显示。 Alternatively use a state (ngrx), actions for the click, selectors to provide the data to the main component.或者使用 state (ngrx),点击动作,选择器向主要组件提供数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 如何使用单击功能根据国家/地区名称提取和显示特定的 JSON 数据 - Angular how to extract and display specific JSON data based on country name using click function 如何根据用户单击父组件中的对象在共享服务的子组件中显示数据? - How to display data in a child component from a shared service based on user click on an object in a parent component? 如何在 Angular 6 中基于点击事件显示唯一元素 - How To Display A Unique Element Based On A Click Event In Angular 6 如何在Angular 6中根据用户输入显示不同的错误消息 - How to display different error messages based on user input in Angular 6 如何基于Firebase中的值存储显示用户输出(角度) - How to display user output based on the value store in the firebase (Angular) 如何在angular 10中点击按钮显示附加数据集? - How to display the additional set of data on click on button in angular 10? 更新 Angular 中的用户数据显示 - Updating User data display in Angular 如何使用 ngTemplateOutlet 以角度显示基于 roomList 数据的模板 - How to display the template based on the roomList data using ngTemplateOutlet in angular Angular 如何显示来自用户的包含数组的数据 - Angular how to display data from user which contain an array 如何基于angular6中的用户输入过滤列表中的数据? - How to filter data on list based on user input in angular6?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM