使用自关闭标签时不显示 AngularJS 元素指令 [英] AngularJS element directives not displaying when using self-closing tags

查看:19
本文介绍了使用自关闭标签时不显示 AngularJS 元素指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 html 文件中有指令

I have in my html file directives

<add />
<back />

并且指令在表单上

.directive('add', ['$window', ...

.directive('back', ['$window', 

这很好用.

如果我将指令更改为驼峰式:

If i change the directives to camel case:

.directive('addPlayer', ['$window', ...

<add_player />
<back />

<add:player />
<back />

显示正常而

<add-player />  regular dash
<back />

仅显示 之后的所有内容均不显示.

displays only <add-player> and everything after is not displayed.

知道为什么吗?

我在这里得到了相同的行为

I've kind of gotten the same behaviour here

http://plnkr.co/edit/cpP4c2TyZwv5Y4BrNUBb?p=preview

推荐答案

为了解决你的问题,我引用 AngularJS 团队的官方声明:(原文如此)

To lay your question to rest, I am quoting the official statement from the AngularJS team: (sic)

html 规范定义的自关闭或空元素对于浏览器解析器来说非常特殊.您无法创建自己的元素,因此对于您的自定义元素,您必须坚持使用非空元素 (</foo>).

self-closing or void elements as the html spec defines them are very special to the browser parser. you can't make your own, so for your custom elements you have to stick to non-void elements (<foo></foo>).

这不能改变角度.

- IgorMinar

- IgorMinar

来源:https://github.com/angular/angular.js/issues/1953#issuecomment-13135021

关注 AngularJS 问题页面上的其余对话,他们讨论了使用 XHTML 传送带有浏览器可接受的自闭合标签的内容的可能性.但是请注意,AngularJS 并不完全支持它.

Follow the rest of the conversation on AngularJS issue's page where they discuss the possibility of using XHTML for delivering content with self-closing tags that is acceptable to the browser. However do note that it is not fully supported by AngularJS.

这篇关于使用自关闭标签时不显示 AngularJS 元素指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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