我目前正在开发一款使用ANGLING 7的网络应用程序,我想加入ngx-toastr来向用户发送通知,但它并没有像预期的那样工作.当我触发祝wine 词时,除了一个 cogo toast 大小的盒子出现在右下角之外,什么都没有发生,但只有当鼠标悬停在侍者的上方时才会出现. 下面是我如何触发toastr函数的一个示例.单击按钮即可调用测试.

import {ToastrService} from 'ngx-toastr';
@Component({
  selector: 'app-action-controls',
  templateUrl: './action-controls.component.html',
  styleUrls: ['./action-controls.component.scss']
})
export class Notification implements OnInit {
  test(){   
          this.toast.success("I'm a toast!", "Success!");
  }
 constructor(private toast: ToastrService) { }
}

我将库CSS文件包含在项目的angular.json文件中,如下所示:

     ...        
     "styles": [
        "src/styles.scss",
        "node_modules/bootstrap/scss/bootstrap.scss",
        "node_modules/ngx-toastr/toastr.css"
      ],
      ...

在我的应用程序中也是这样.单元ts文件:

...
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {ToastrModule} from 'ngx-toastr';
...
  imports: [
    ...
    BrowserAnimationsModule,
    ToastrModule.forRoot({
      timeOut: 1000,
      positionClass: 'toast-bottom-right'
    })
   ]
...

我不知道我做错了什么,有人有过类似的经历吗?非常感谢您提前到场!

推荐答案

我对你的问题做了最低限度的复制,我看不出有什么问题: https://stackblitz.com/edit/angular-avcidu

您是否有可能有一些与toastr冲突的自定义样式.css样式,还是格式错误的模板(例如未关闭的div)?

您使用的是最新版本的ngx toastr吗?(9.1.1担任本职位时)

您的模板是什么样子的?

Update:

之前的stackblitz现在显示了复制的问题.这里是链接:https://stackblitz.com/edit/angular-avcidu

看起来bootstrap和ngx toastr都使用了.toastr类,影响toastr div的不透明度属性.

这个线程有一个可行的答案:Setting toastr opacity?

其中的答案是强制不透明度为1.在自定义样式表中添加以下内容:

#toast-container > div {
    opacity:1;
}

这是正在进行的闪电战:https://stackblitz.com/edit/angular-gjazzq

Angular相关问答推荐

导致无限请求的Angular HttpInterceptor和HttpClientModule

角material 17 -如何从Style.scss中的主题中获取原色

如何包装NGB carousel ?

我正在try 将一个带有模块联盟的Angular 8项目expose 到另一个Angular 项目,Angular 是15,这可能吗?如果是这样,有什么建议吗?

如何将Angular 服务包含在延迟加载的独立组件路由中?

从API动态加载MAT表数据时禁用分页

如何让 ag-Grid 事件读取私有方法?

Angular 13 Sass 模块无法在编译中正确导入文件

Angular:如何在根组件中使用 ngx-translate?

您如何链接需要多个先前可观察对象的依赖订阅

Angular 项目构建仅在 GitHub Actions 上失败

在 Angular material表上调用 renderRows()

Angular 2:Validators.pattern() 不工作

Angular2 Pipes:输出原始 HTML

Angular 2 - 全局 CSS 文件

Failed to execute 'setAttribute' on 'Element': ']' is not a valid attribute name

路由 getCurrentNavigation 始终返回 null

declarations和entryComponents组件有什么区别

ngClass 中的多个条件 - Angular 4

'ng' 不是内部或外部命令、可运行程序或批处理文件