简体   繁体   English

MatToolTip 在 Angular 中无法正常工作

[英]MatToolTip is not working properly in Angular

I am using MatToolTip in one of my lazy loaded modules, and I am not getting any error, but all the tooltip texts ( that are provided to the matTooltip property ) are shown on the left bottom corner of the screen and not on the element where the tooltip is supposed to show.我在我的一个延迟加载模块中使用 MatToolTip,我没有收到任何错误,但是所有工具提示文本(提供给 matTooltip 属性)都显示在屏幕的左下角,而不是显示在工具提示应该显示。

It was working just fine when I was using Angular 9, but now I moved Annular 11 and the texts are not in their appropriate positions当我使用 Angular 9 时它工作得很好,但现在我移动了 Annular 11 并且文本不在适当的位置

Here is the html code where I am using matToolTip这是我使用 matToolTip 的 html 代码

 <div
      mat-raised-button
      matTooltip="No changes made"
      [matTooltipDisabled]="active"
      [class.save-active]="active"
      (click)="save.emit()"
      class="save"
 >
  {{ text }}
 </div>

This is how my SharedModule looks like这就是我的 SharedModule 的样子

import { MatTooltipModule } from '@angular/material/tooltip';

@NgModule({
...,
 imports: [..., MatTooltipModule,],
 exports: [...,  MatTooltipModule,],
})

export class SharedModule {}

and this is how my AppModule looks like这就是我的 AppModule 的样子

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
...,
 imports: [
     ...,     
     BrowserModule,
     BrowserAnimationsModule
 ]
})

export class AppModule {}

Anyone has an idea what might be going on?任何人都知道可能会发生什么?

Try adding the Material CSS inside your styles.css like this:尝试在 styles.css 中添加材料 CSS ,如下所示:

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM