Angular 2:是相对于当前组件的styleUrl
Angular 2: is styleUrls relative to the current component?
使用styleUrls
为angular 2组件添加样式时遇到了一些麻烦。
以下是我如何使用它:
路径/main.component.ts
@Component({
selector: 'app-view',
styleUrls: ['./styles/style.css'],
template: //...
})
path/styles/style.css
.main-wrapper {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
background: red; }
我的浏览器什么也没发生。我尝试过:
- 绝对路径
- 相对于根组件的路径
我也试过:
- 使用不同的语法(如
'./styles/style.css'
、'styles/style.css'
)编写 - 将我的
style.css
移到我的组件旁边
但我不能让它发挥作用。
不要使用styleUrls
。只需使用scss
扩展名重命名样式文件即可。样式表将自动使用!
因此,我的组件文件将是这样的,并且将使用以下样式:
- mycomponent.ts
- mycomponent.html
- mycomponent.scss
相关文章:
- React重新渲染但未显示正确的组件
- 不能从angular2中的子组件指定父组件中的数组
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- React组件等待所需道具进行渲染
- 如何创建带有插槽的vue js组件预加载程序
- KnockoutJS-组件-多个实例
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何在react js中将值从一个组件发送到另一个组件
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- React组件-设置页面标题
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- 如何在salesforce aura闪电组件中使用jQuery.val()
- 为react组件传递道具的最佳方式
- [Vue warn]:未能解析组件
- 如何控制组件'的createContent函数被激发
- react组件中的绑定方法
- 如何在react js中移动第二个组件
- 多个组件是如何实现的
- 组件生命周期问题/无法处理未定义的问题
- Angular 2:是相对于当前组件的styleUrl