用什么代替:: ng-deep [英] What to use in place of ::ng-deep
问题描述
我正在尝试将路由器插座放置的元素设置为有角度的样式,并希望确保生成的元素的宽度为100%
I'm trying to style an element placed by the router outlet in angular and want to make sure that the element generated gets a width of 100%
从大多数答复中,我看到我应该使用::ng-deep
选择器,但是从Angular的
From most of the replies, I'm seeing that I should use the ::ng-deep
selector, but from Angular's docs it is being deprecated. Is there an alternative to ::ng-deep
?
推荐答案
FWIW在我的研究中,我没有发现ng-deep的任何替代品或其他适用的替代品.我相信这是因为,Angular团队正在遵循影子dom的W3C规范,该规范最初具有诸如deep
之类的选择器.但是,W3c自此删除了该建议,但未用新建议取代它.在此之前,我想像Angular团队将保留::ng-deep
及其可用的替代方案,但由于W3C草案的待定状态而处于弃用状态.我现在无法花时间来找到支持该文档的文档,但是最近才看到它.
FWIW In my research I have not found any replacement for ng-deep or the other applicable alternatives. This is because, I believe, the Angular team is deferring to the W3C spec on the shadow dom, which initially had selectors such as deep
. However, the W3c has since removed the recommendation, but not replaced it with a new one. Until that happens, I imagine that the Angular team will keep ::ng-deep
and it's alternatives available, but in deprecated state due to the pending state of W3C's drafts. I am not able to take the time to find the documentation to back this up right now but I did see it recently.
长话短说:继续使用::ng-deep
及其替代方法,直到创建替代项为止-弃用只是一个早期通知,因此,只要实际的更改实现,人们就不会盲目.
Long story short: Keep using ::ng-deep
and its alternatives until a replacement is created - the deprecation is just an early notice so that people aren't blindsided whenever the actual change materializes.
-更新-
https://drafts.csswg.org/css-scoping-1/ 如果您有兴趣,这是建议草案.看来他们正在为影子dom树中的元素选择器的强大集合.我认为正是该规范一旦获得批准,便会通知角度克隆(如果有的话)(即,一旦在浏览器中启用,角度可能不需要实现自己的选择器).
https://drafts.csswg.org/css-scoping-1/ Here is the draft proposal if you're interested. It appears that they are working on a robust set of selectors for elements within a shadow dom tree; it is this spec, once approved, that I think will inform the angular clone, if there even is one (i.e. angular may not need to implement their own selectors once this goes live in browsers).
这篇关于用什么代替:: ng-deep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!