我有一个Angular2应用程序。此代码正确加载stylesArr
:
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
:
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 {
...
这是我的文件结构:
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中存在特定的查询字符串,我将有条件地向数组添加第二个样式表。)
答案 0 :(得分:0)
将路径修改为
var stylesArr = ['/open-account.component.scss'];
如果这不起作用,请使用文件夹结构更新帖子