简体   繁体   English

AngularJS 1.5:用html标签替换组件标签

[英]Angularjs 1.5: replace component tag with html tag

I have an angular 1.5 app that makes extensive use of components. 我有一个Angular 1.5应用程序,可以广泛使用组件。 My issue is that the that my custom component tags are failing accessibility testing. 我的问题是自定义组件标签的可访问性测试失败。 My view model templates look like this: 我的视图模型模板如下所示:

<my-component data='myModel'></my-component>

<script type="text/ng-template" id=myComponent.html">
    <pre> {{ data | json }} </pre>
</script>

This will result in this rendered in the live DOM: 这将导致它在实时DOM中呈现:

<my-component data='myModel'>
    <pre>
        ...
    </pre>
</my-component>

the my-component tag is not recognized by our testing tools and fails accessibility. 我的测试工具无法识别my-component标签,并且无法访问。

I have looked into transforming the my-component tags to divs, but cannot figure out how. 我已经研究过将my-component标记转换为div,但无法弄清楚该怎么做。 Directives in 1.5 have the replace function. 1.5中的指令具有替换功能。 Components in 2.0 have the selector property. 2.0中的组件具有选择器属性。 I don't believe I can achieve this using transclusion either (because it would my-component's controller would need to reference its parent tag). 我也不相信我可以使用包含来实现这一点(因为my-component的控制器将需要引用其父标记)。

Am I thinking about this the right way? 我在考虑正确的方法吗? Perhaps I should be using ng-Aria for screen readers to ignore these tags? 也许我应该为屏幕阅读器使用ng-Aria来忽略这些标签? Has anyone run into this problem? 有没有人遇到这个问题?

You shouldn't change the element's tag, but you should add aria tags natively when possible, or by angular aria. 您不应该更改元素的标签,但是应该在可能的情况下本机添加aria标签,或者通过角度aria添加。 Read Angular accessibility guide . 阅读Angular辅助功能指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM