首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular2 - stylesArr无法正确加载

Angular2 - stylesArr无法正确加载
EN

Stack Overflow用户
提问于 2017-02-14 00:27:23
回答 1查看 21关注 0票数 0

我有一个Angular2应用程序。这段代码正确加载了我的stylesArr

代码语言:javascript
复制
import { Component, OnInit, AfterViewChecked, OnDestroy, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router, Params } from '@angular/router';
...

import * as c3 from 'c3';

@Component({
  selector: 'open-account',
  styleUrls: ['./open-account.component.scss'],
  templateUrl: './open-account.component.html',
})


export class OpenAccountComponent implements OnInit, AfterViewChecked, OnDestroy, AfterViewInit {
...

但是,当我将此代码与stylesArr数组一起使用时,我得到错误http://localhost:3000/open-account.component.scss 404 (Not Found) & Failed to load open-account.component.scss

代码语言:javascript
复制
import { Component, OnInit, AfterViewChecked, OnDestroy, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router, Params } from '@angular/router';
...

import * as c3 from 'c3';

var stylesArr = ['./open-account.component.scss'];

@Component({
  selector: 'open-account',
  styleUrls: stylesArr,
  templateUrl: './open-account.component.html',
})


export class OpenAccountComponent implements OnInit, AfterViewChecked, OnDestroy, AfterViewInit {
...

下面是我的文件结构:

代码语言:javascript
复制
web-frontend
│       
│
└───src
    │   
    └───open-account
        └───index.ts
        └───open-account-widget-styles.component.scss
        └───open-account.component.html
        └───open-account.component.scss
        └───open-account.component.ts
        └───open-account.module.ts
        └───open-account.routes.ts
        └───open-account.service.ts

为什么第二种方法不起作用?它们的功能不应该完全相同吗?(ps。我需要使用数组形式,因为如果url中存在特定的查询字符串,我将有条件地向数组添加第二个样式表)。

EN

回答 1

Stack Overflow用户

发布于 2017-02-14 00:37:34

将路径修改为

代码语言:javascript
复制
var stylesArr = ['/open-account.component.scss'];

如果这不起作用,请使用文件夹结构更新您的帖子

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42208875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档