0
我有一個Angular2應用程序。此代碼加載我stylesArr
正確: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中存在特定的查詢字符串,我將有條件地向數組添加第二個樣式表)。
感謝,但沒有工作,我更新後與我的文件結構 – joseg
也去掉前面的斜線和更新我是否可以正常工作 – Aravind
沒有工作,以及,我終於實現了這個(其中沒有工作): ''' @Component({ 選擇:「開放賬戶」, styleUrls:「開放-account.compon ent.scss','open-account-widget-styles.component.scss']。filter((elem,i)=> {if(i === 0)return true;如果(i == 1){window.location.href.indexOf('widget = true')> -1)return true; 否則返回false; } }), templateUrl:'./open-account.component.html', }) ''' – joseg