用什么代替 ::ng-deep [英] What to use in place of ::ng-deep

查看:61
本文介绍了用什么代替 ::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 的 docs 它已被弃用.有没有 ::ng-deep 的替代品?

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 团队正在遵循 W3C 关于 shadow dom 的规范,该规范最初具有诸如 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.c​​sswg.org/css-scoping-1/如果您有兴趣,这里是提案草案.看起来他们正在为 shadow dom 树中的元素开发一组强大的选择器;正是这个规范,一旦获得批准,我认为会通知 angular 克隆,如果有的话(即,一旦它在浏览器中上线,angular 可能不需要实现自己的选择器).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆