Angular2-将css文件实现到组件中

Angular2-将css文件实现到组件中,css,angular,components,Css,Angular,Components,我的组件中包含以下内容: @Component({ selector: 'Leaders', template: require('./Leaders.component.html'), styleUrls: ['./bootstrap.component.css'] }) 在我将此样式表添加到组件之前,该组件加载良好。当我尝试运行我的web应用程序时,它说它“无法读取css文件所在的URL”。此css文件与我的Leader html页面位于同一文件夹中,但它找不到该文件。我做错了什么?我该如

我的组件中包含以下内容:

@Component({
selector: 'Leaders',
template: require('./Leaders.component.html'),
styleUrls: ['./bootstrap.component.css']
})
在我将此样式表添加到组件之前,该组件加载良好。当我尝试运行我的web应用程序时,它说它“无法读取css文件所在的URL”。此css文件与我的Leader html页面位于同一文件夹中,但它找不到该文件。我做错了什么?我该如何修复它?

我无法评论,我将写下这篇文章作为答案

模板中使用
require(…)
是否有具体原因

如果没有,请尝试此操作,并确保您的
css
文件名拼写正确:

 @Component({
    selector: 'Leaders',
    templateUrl: './Leaders.component.html',
    styleUrls: ['./bootstrap.component.css']
 })
希望这有帮助

我无法发表评论,我将写下这篇文章作为回答

模板中使用
require(…)
是否有具体原因

如果没有,请尝试此操作,并确保您的
css
文件名拼写正确:

 @Component({
    selector: 'Leaders',
    templateUrl: './Leaders.component.html',
    styleUrls: ['./bootstrap.component.css']
 })

希望这有帮助

您正在使用Angular2的旧版本。对于较新版本,使用的语法为:

  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css']

请注意,没有不应该存在的
require()

您使用的是Angular2的旧版本。对于较新版本,使用的语法为:

  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css']

请注意,没有
require()
那不应该在那里。

我已经取出require并切换到templateURL,现在它说它无法读取该URL您使用的angular版本是什么?我使用的是版本2.1我已经取出require并切换到templateURL,现在它说它无法读取该URL您使用的angular版本是什么?我使用的是版本2.1可以吗是否尝试使用相对于根的路径
'app/../Leaders.component.html'
它没有抛出错误,但没有实现tsconfig中的所有样式,
“模块”中的内容:
?我刚刚将其更改为module:commonjs。如果要使用相对于组件的路径,则需要在组件中使用moduleId。将
moduleId:module.id
添加到组件装饰器中,然后使用
'./Leaders.component.html'
'./bootstrap.component.css'
可以尝试使用相对于根的路径吗
'app/../Leaders.component.html'
它没有抛出错误,但没有实现tsconfig中的所有样式,
“模块”中的内容:
?我刚刚将其更改为module:commonjs。如果要使用相对于组件的路径,则需要在组件中使用moduleId。将
moduleId:module.id
添加到组件装饰器中,然后使用
'./Leaders.component.html'
'./bootstrap.component.css'