css - Angular 5 自定义组件 CSS

标签 css angular

我有一个 CSS 文件,我只想在页面上有组件时加载它。

我尝试了以下方法:

@Component({
  selector: 'testview-testview',
    templateUrl: './templates/testview.html',
    styles: [
        "../../../assets/vendors/custom/reveal.js-3.6.0/css/reveal.css",
        "../../../assets/vendors/custom/reveal.js-3.6.0/css/theme/black.css"
    ],
})

但是没有任何运气。有谁知道这样做的方法吗?

编辑

所以我试图按照下面的答案

这是我的文件夹结构:

enter image description here

我的组件现在看起来像这样:

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

declare var Reveal: any;

@Component({
    selector: 'testview-testview',
    templateUrl: './templates/testview.html',
    styleUrls: ['./templates/testview.css'],
})
export class TestviewComponent implements OnInit {

    constructor() {
    }


    ngOnInit() {
        Reveal.initialize({});
    }

}

我的 testview.css 文件如下所示:

    @import url("../../../assets/vendors/custom/reveal.js-3.6.0/css/reveal.css");
@import url("../../../assets/vendors/custom/reveal.js-3.6.0/css/theme/black.css");

最佳答案

你必须在样式数组中的 url 中:styleUrls instead of styles

所以

@Component({
  selector: 'testview-testview',
    templateUrl: './templates/testview.html',
    styleUrls: [
        "../../../assets/vendors/custom/reveal.js-3.6.0/css/reveal.css",
        "../../../assets/vendors/custom/reveal.js-3.6.0/css/theme/black.css"
    ],
})

编辑:

@Component({
  selector: 'testview-testview',
    templateUrl: './templates/testview.html',
    styleUrls: ['./templates/testview.css'

    ],
})

在你的 css ./templates/testview.css 导入文件

@import url("../../../assets/vendors/custom/reveal.js-3.6.0/css/reveal.css");
@import url("../../../assets/vendors/custom/reveal.js-3.6.0/css/theme/black.css");

关于css - Angular 5 自定义组件 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50484531/

相关文章:

javascript - 让父级滚动到某个点,然后子级在父级内部滚动

html - 使用 HTML/CSS 将可变大小数据/文本列表与相应的标签/文本对齐

javascript - 在 AngularJS 中将变量从 HTML 传递到 Javascript 时,与整个对象相比,性能有何改进

Angular Universal - Auth Guard 未决问题

javascript - 防止除弹出窗口及其内容外的所有元素滚动

javascript - 在 Magnific Popup 插件中使用时,无法从 Spectrum Colorpicker 插件中的文本框复制颜色

css - 少覆盖类和子

angular - 如何将 ngrx-effect 中的 Action 的 action.payload 传播到 catchError 或 map 运算符?

Angular 4 动态表单组

angular - 使用 jasmine spy 测试 cdk 覆盖