【发布时间】:2019-07-10 15:36:21
【问题描述】:
我在 Angular 2 的“app/Hero”下定义了一个“Hero”组件。英雄组件定义为“hero.component.html”、“hero.component.css”和“hero.component.ts”文件. templateUrl 工作正常,但 styleUrls 不加载。将显示资源未找到错误。我引用了这个链接 https://angular.io/docs/ts/latest/guide/component-styles.html#!#relative-urls 来使用相对 URL 加载样式。
@Component({
providers: [HeroService],
templateUrl: './Hero.component.html',
styleUrls: ['./Hero.component.css'],
})
【问题讨论】:
-
去掉逗号。 css'],Hero 使用小写
-
请在文件夹结构中添加文件名
-
@kimy82 我删除了最后一个逗号。但我仍然收到错误:加载资源失败。
-
是的,我认为您可能必须设置选择器 selector: 'hero-component', 并将提供程序移动到 app.module.ts 。确保你没有使用 less 而不是 css 文件
标签: css angular typescript angular-components