Angular 角度2不工作
我不确定这里少了什么。我已经按照上的指南使用了组件样式的URL。但是当我运行组件时,没有应用样式。但是,如果我使用组件内联样式,它会工作 培训 training.component.html webpack.common.js 有效的组件内联样式Angular 角度2不工作,angular,webpack,Angular,Webpack,我不确定这里少了什么。我已经按照上的指南使用了组件样式的URL。但是当我运行组件时,没有应用样式。但是,如果我使用组件内联样式,它会工作 培训 training.component.html webpack.common.js 有效的组件内联样式 @Component({ templateUrl: './training.component.html', styles: [` .notification-message { border: 2px solid black; background-
@Component({
templateUrl: './training.component.html',
styles: [`
.notification-message {
border: 2px solid black;
background-color: #ffff00;
color: #ff0000;
width: 100%;
text-align: left;
padding-left: 6px;
padding-right: 6px;
padding-bottom: 2px;
font-size: 11px;
font-family: Verdana, Helvetica, Sans-Serif;
font-weight: bold;
}`]})
我能找出问题所在。我不得不在网页包配置中使用字符串加载器 这在webpack.common.js中对我有效
{
test: /\.(css)$/,
loaders: ['to-string-loader', 'css-loader']
}
尝试删除斜杠样式URL:['training.component.css']^^尝试不使用/我尝试了不使用/但仍然不起作用。目前仅使用内联样式。请确保trainig.component.css与training.component.ts位于同一目录中(样式URL:['./training.component.css']是可以的),并且没有与.notification message类重叠的css
.notification-message {
border: 2px solid black;
background-color: #ffff00;
color: #ff0000;
width: 100%;
text-align: left;
padding-left: 6px;
padding-right: 6px;
padding-bottom: 2px;
font-size: 11px;
font-family: Verdana, Helvetica, Sans-Serif;
font-weight: bold;
}
module: {
rules: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
options: { configFileName: helpers.root('', 'tsconfig.json') }
}, 'angular2-template-loader'
]
},
{test: /\.html$/,loader: 'html-loader'},
{ test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/, loader: 'url-loader' },
{ test: /\.css$/, loader: 'raw-loader!css-loader' }
]
},
plugins: [
new CleanWebpackPlugin(['built'], { root: '' }),
//Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./scripts/app'), // location of your src
{} // a map of your routes
),
new webpack.optimize.CommonsChunkPlugin({
name: "commoncode",
filename: "commoncode.js",
chunks: ["app", "vendor", 'kendoVendor'],
minChunks: Infinity,
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
/*in order to automatically load bundled js files on layout page, use this plugin and do appropriate changes.
new HtmlWebpackPlugin({
inject: false,
template: './Views/Shared/_LayoutTemplate.cshtml',
filename: './Views/Shared/_Layout.cshtml'
})*/
]
@Component({
templateUrl: './training.component.html',
styles: [`
.notification-message {
border: 2px solid black;
background-color: #ffff00;
color: #ff0000;
width: 100%;
text-align: left;
padding-left: 6px;
padding-right: 6px;
padding-bottom: 2px;
font-size: 11px;
font-family: Verdana, Helvetica, Sans-Serif;
font-weight: bold;
}`]})
{
test: /\.(css)$/,
loaders: ['to-string-loader', 'css-loader']
}