Angular component文件夹中的component.scss不工作
当我在Angular component文件夹中的component.scss不工作,angular,sass,Angular,Sass,当我在component.scss中放置样式代码时,它不会影响引用的目标,但是当我在src/scss/style.scss中放置样式代码时,它工作得非常好。有人知道问题出在哪里吗 如果它缺乏技术知识,请向我提供一些资料供我学习。如果您试图在子组件内部设置样式,它将无法工作。您应该在scss中使用ng deep 在组件中,注意作为StyleUrl给出的内容: @Component({ selector: 'app-something', templateUrl: './something.
component.scss
中放置样式代码时,它不会影响引用的目标,但是当我在src/scss/style.scss
中放置样式代码时,它工作得非常好。有人知道问题出在哪里吗
如果它缺乏技术知识,请向我提供一些资料供我学习。如果您试图在子组件内部设置样式,它将无法工作。您应该在scss中使用ng deep
在组件中,注意作为StyleUrl给出的内容:
@Component({
selector: 'app-something',
templateUrl: './something.component.html',
styleUrls: ['./something.component.scss']
})
可能您的语法不好,或者您引用的是一个简单的
某物.component.*css**
而不是.scss
文件 对于我,我需要设置ViewEncapsulation.None
,我的样式URL
才能生效:
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-testing',
templateUrl: './testing.component.html',
styleUrls: ['./testing.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class TestingComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
我不知道为什么这是必要的。至少在Angular 8中需要它,但谢天谢地,Angular 9中不需要它。我不确定它是否会帮助您,但对我来说,问题是因为我在组件中使用了样式[],因此它无法读取.scss文件
@Component({
selector: 'myse-draft-order',
styleUrls: ['./something.component.scss'],
templateUrl: './something.html',
styles: [], // needs to be removed.
})
你是对的。angular cli不会在
@Component
decorator中创建样式URL。非常感谢。谢谢你!有时候简单就是简单:-)在找到你的答案之前,我不得不涉过~6个无用的线程。:ng deep
被弃用:@xinthes/deep/被弃用::ng deep就在这里:-)@alexKhymenko好的。我当时听别人说错了。感谢您的澄清。这在我的情况下起到了作用。非常感谢。请阅读本文,其中有许多解决方案()
@Component({
selector: 'myse-draft-order',
styleUrls: ['./something.component.scss'],
templateUrl: './something.html',
styles: [], // needs to be removed.
})