加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 从Angular 2组件中的CDN加载css

发布时间:2020-12-17 06:55:56 所属栏目:安全 来源:网络整理
导读:正如标题所说,我想在Angular 2组件中包含外部css.以下是我现在的表现: import { Component,OnInit } from '@angular/core';@Component({ selector: 'app-auth',templateUrl: './auth.component.html',styleUrls: [ 'https://fonts.googleapis.com/css?famil
正如标题所说,我想在Angular 2组件中包含外部css.以下是我现在的表现:

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

@Component({
    selector: 'app-auth',templateUrl: './auth.component.html',styleUrls: [
        'https://fonts.googleapis.com/css?family=Dosis:400,500,600,700','http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css','./assets/css/bootstrap.min.css','./assets/css/main.css','./assets/css/responsive.css','./auth.component.css',],})
export class AuthComponent implements OnInit {

    constructor() { }

    ngOnInit() {
    }

}

前两个网址不起作用.我收到一个错误:

ncaught错误:找不到模块“./https://fonts.googleapis.com/css?family=Dosis:400,700”

我可以通过将其直接包含在HTML中来使其工作,但我认为这不是正确的方法.

编辑:我甚至尝试使用封装:ViewEncapsulation.None,这没有帮助.

解决方法

您应该只在styleUrls数组中加载本地样式.因此,在auth.component.css中,导入所需的外部样式表:

@import "https://fonts.googleapis.com/css?family=Dosis:400,700";
@import "http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读