angular - Include external CSS in an Angular library
问题描述
I'm creating an Angular library that needs to use tippy.js. Basically, I'm creating a wrapper of it. I know that packages to do so already exist, but I'm doing it for learning purposes.
For now, the directive is really simple:
import { Directive, ElementRef, OnInit } from '@angular/core';
import tippy from 'tippy.js';
import 'tippy.js/dist/tippy.css';
@Directive({
selector: '[tooltip]'
})
export class TooltipDirective implements OnInit {
constructor(private _element: ElementRef) { }
public ngOnInit(): void {
tippy(this._element.nativeElement, { content: this._element.nativeElement.getAttribute('tooltip'), arrow: true });
}
}
It works, but the issue is that I don't get the styling of the tooltip.
I guess referencing it via an import
like this is not the way to go.
Note that I have different components in the library, all included in different modules and I'd like the CSS of tippy.js to be imported only where I import the module containing my directive.
I don't really know where and how I'm supposed to import my CSS in a clean way.
Any advices?
解决方案
添加@import '~tippy.js/dist/tippy.css';
到根目录下的style.css
推荐阅读
- facebook - 如何获取 Facebook Marketplace 目录产品的公共 URL
- f# - 使用 Elmish.wpf/F#,如何在 WPF 中将字符串选项显示为字符串或 null,而不是“Some(string)”?
- powershell - 如何从 Foreach 中的第二个 CSV 检索关联值
- angular - 离子页脚最佳实践
- json - 在 Swift 中编码空嵌套结构时,如何省略空大括号?
- javascript - 仅使用 javascript 移动框
- javascript - Bootstrap v4.0 中的表单验证不起作用,所需的标签不起作用
- css - css float:清除和浮动都不起作用
- javascript - 如果我有多个 ul 并且所有 li 都具有相同的类名,我如何获得特定于 ul 的 li
- node.js - 尝试在 React/Node 设置中使用 Google+ API 进行身份验证时,工作设置中出现 CORS 错误