設置StyleUrls可變我有一個ts
文件中像這樣如何在角2
export const environment = {
production: false,
profile : './test/test.css'
};
我想進口environment.profile
,並設置它,這樣我可以在StyleUrls使用它像
import { Component, OnInit } from '@angular/core';
import { TranslateService } from "@ngx-translate/core";
import {environment} from "../../environments/environment";
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: [environment.profile]
})
但我得到的錯誤:
Error: Cannot find module "." main.bundle.js:250:62 webpackMissingModule http://localhost:4200/main.bundle.js:250:62 ../../../../../src/app/header/header.component.ts http://localhost:4200/main.bundle.js:250:29 webpack_require http://localhost:4200/inline.bundle.js:55:12 ../../../../../src/app/app.module.ts http://localhost:4200/main.bundle.js:71:83 webpack_require http://localhost:4200/inline.bundle.js:55:12 ../../../../../src/main.ts http://localhost:4200/main.bundle.js:291:74 webpack_require http://localhost:4200/inline.bundle.js:55:12 [2] http://localhost:4200/main.bundle.js:309:18 webpack_require http://localhost:4200/inline.bundle.js:55:12 webpackJsonpCallback http://localhost:4200/inline.bundle.js:26:23 http://localhost:4200/main.bundle.js:1:1 [WDS] Warnings while compiling. vendor.bundle.js:13428:10 ./src/app/header/header.component.ts 32:17-45 Critical dependency: the request of a dependency is an expression vendor.bundle.js:13493:4
我不知道如何解決它可以someo ne幫我
它指的是我的css的確切路徑 – user2843943
你可以嘗試把一個硬編碼的字符串,而不是變量? (只是爲了確認問題是什麼) –
工作正常 – user2843943