简体   繁体   English

如何使用modalService使用情况将自定义css添加到ngx-bootstrap模态(请参见下面的原因)?

[英]How to add custom css to ngx-bootstrap modal with modalService useage(see reasons below)?

I have a very niche use-case. 我有一个非常特殊的用例。 I have to add a modal animation like this: regular css animation But I need to have a component (our own filter component for a datatable) inside said modal. 我必须添加一个这样的模式动画: 常规的CSS动画但是我需要在所述模式内部有一个组件(我们自己的用于数据表的过滤器组件)。 So I need to use the ModalService. 所以我需要使用ModalService。 But this service is only attaching my custom config like this: 但是此服务仅附加我的自定义配置,如下所示:

  toggleFilter = () => {
    const modalOptions: ModalOptions = {
      initialState: {
        labels: this.datatableLabels, // needed for filter to have labels
        filterGroups: this.filterGroups // needed to add filterGroups
      },
      class: 'filter-modal' // this sould be my custom class
    };
    this.bsModalRef = this.modalService.show(FilterComponent, modalOptions);
  }

to modal-content and the above mentioned animation and styling uses divs above that. modal-content ,上述动画和样式在此之上使用div。 Not only it's working when encapsulation set to ViewEncapsulation.None then it screws our other modals as well, since I cannot apply correct classes to the one I need to mess with. 当封装设置为ViewEncapsulation.None时,它不仅可以正常工作,而且也不会ViewEncapsulation.None我们的其他模式,因为我无法将正确的类应用于需要处理的类。

How can I overcome this issue I'm having? 如何解决我遇到的这个问题?

Instead of using the ModalService and open desired embedded component within the modal. 代替使用ModalService并在模态中打开所需的嵌入式组件。 You can basically inject the desired component into the body of the modal while using directive instead -> Here you are declaring the whole modal layout -> you can modify all the related classes so it's easier to modify a modal and have your ViewEncapsulation untuched so other modals are unaffected. 您基本上可以在使用指令的同时将所需的组件注入到模态主体中->在这里,您声明了整个模态布局->您可以修改所有相关的类,以便更轻松地修改模态并解开ViewEncapsulation,以便其他模态不受影响。

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

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