【问题标题】:Is there any way to hide the components of the app component in Angular?有什么方法可以在 Angular 中隐藏 app 组件的组件吗?
【发布时间】:2021-04-30 23:14:47
【问题描述】:

我正在开发聊天软件 UI。我在 app.component.html 中编写了工具栏。 然后我在单独的组件中编写了登录和注册按钮并路由它们。最初我的主页是这样的。Please click on the link to view the image

当我点击登录或注册时,它将如下所示。 Please click on the link to view the image

登录后,工具栏仍然包含登录和注册按钮,我该如何隐藏这些?下面是我的 app.component.html

`<mat-toolbar class = "tb">
  <span class = "tit">My App</span>
  <span class="example-spacer"></span>
  <button mat-stroked-button class="lb" routerLink = "log">Login</button>
  <button mat-stroked-button class="rb" routerLink = "reg">Register</button>
</mat-toolbar>
<router-outlet></router-outlet>`

下面是我的 app.component.ts 代码

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'demo';
}

【问题讨论】:

    标签: angularjs frontend toolbar


    【解决方案1】:

    在元素中简单地设置一个 [hidden]="!show"(登录/注册链接)。

    类似: login(){ userService.loggedIn = true; this.show = false; }

    【讨论】:

    • 你能告诉我更详细的描述吗?我需要在哪个文件中粘贴上面的代码。我是新手
    • 您有一个用于创建登录/注册的导航栏组件。如果你有类似&lt;a href="#" [hidden]="!show"&gt;login&lt;/a&gt; 的东西。那么导航栏组件应该有 this.show 并将其设置在那里
    • 跟随官方教程angular.io/tutorial/toh-pt4,Services are a great way to share information among classes that don't know each other.
    猜你喜欢
    • 2021-09-19
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 2021-04-21
    相关资源
    最近更新 更多