[英]injecting child component into parent distorts the style
I have asked this before and others did but for the life of me, I still can't fix it. 我之前曾问过这个,其他人也曾问过,但对于我的一生,我仍然无法解决。 Here is a stackblitz for you to see: https://stackblitz.com/edit/angular-dpcbxm
这是一个让您看到的stackblitz: https ://stackblitz.com/edit/angular-dpcbxm
which is pretty descriptive. 这非常具有描述性。 I honestly have read a lot about view encapsulation and how it affects injected child components but the 3 settings didn't change anything (nor I want to mess with it in the first place).
老实说,我已经阅读了很多有关视图封装及其如何影响注入的子组件的信息,但是这3个设置没有任何改变(我也不希望一开始就弄乱它)。 I tried doing it via selector: '[hello]' then ..... as well but it changes nothing.
我尝试通过选择器:'[hello]'然后也执行...,但是它什么也没有改变。
I notice a lot of styles are inserted such as ng_content-c4, c6... while I don't know why the child component would have different values than others, I do get they are internal. 我注意到插入了许多样式,例如ng_content-c4,c6 ...虽然我不知道为什么子组件的值会与其他组件不同,但我知道它们是内部的。
In the angular encapsulation page, I did see about styling such components [_ng_content-c6] etc but they are applied to different elements of the child component at a given time that I don't know what to style nor what style to define for them since the style I need is defined for them. 在角度封装页面中,我确实了解了有关对此类组件[_ng_content-c6]等进行样式设置的信息,但是在给定的时间将它们应用于子组件的不同元素,我不知道该如何样式化,也不知道为其定义什么样式因为我需要为他们定义样式。
Can someone take a look and help me fix it? 有人可以看一下并帮助我修复它吗?
I was able to apply the styles defined on the parent to the child component by disabling style encapsulation. 通过禁用样式封装,我能够将在父项上定义的样式应用于子组件。
On Parent: 在父母上:
import {ViewEncapsulation} from '@angular/core';
and also 并且
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
encapsulation: ViewEncapsulation.None
})
I'm getting some erros on the Blitz you share, but at least styling is working. 我在分享的闪电战中遇到了一些麻烦,但至少可以使用样式。 https://stackblitz.com/edit/angular-4grbtd
https://stackblitz.com/edit/angular-4grbtd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.