指令不被呼吁元素和结束标记,但对自闭工作正常 [英] Directive not being called for element with closing tag, but works fine on self-closing

查看:155
本文介绍了指令不被呼吁元素和结束标记,但对自闭工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个指令,以简化我的HTML,但它没有被应用到被写为元素<等等>< /等等> ,即使它被调用时写成元素<嗒嗒/>

I am writing a directive to simplify my HTML, but it is not being applied to elements that are written as <blah></blah>, even though it is being called to elements written as <blah />:

HTML

<search-filter type="text" name="query" update="doSearch()"/>
<search-filter type="bool" name="xp">XP Levels</search-filter>
<search-filter type="bool" name="lotd">LOTDs</search-filter>

指令:

angular.module("blah", [])
.directive("searchFilter", function($compile) {
    return {
        restrict: "E",
        terminal: true,
        priority: 1000,
        compile: function(element, attrs) {
            element = angular.element(element);
            console.log(element);
            switch (element.attr("type")) {
            case "text":
                //do stuff
                break;
            case "bool":
                //do stuff
                break;
            }
        }
    };
})

它适用于第一元件,它是自闭的,但不是其他人。

It works for the first element, which is self-closing, but not the other ones.

推荐答案

在HTML 5,&LT;搜索过滤器/&GT; 办法&LT ;搜索滤光器&gt; 。因此,你永远不会关闭其prevents其他两个工作的第一要素。使用&LT;搜索滤光器&gt;&LT; /搜索滤光器&gt; 所有,它会正常工作

In HTML 5, <search-filter /> means <search-filter>. Therefore you are never closing the first element which prevents the other two to work. Use <search-filter></search-filter> for all and it will work fine.

从W3C

如果该元素是空隙元件中的一个,或者如果元件是
  外国的元素,那么有可能是一个U + 002F SOLIDUS字符
  (/)。这和性格上无效元素没有影响,但对外资
  元素它标志着开始标记为自闭。

If the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

您的指令被视为的空元素的。外国元素是从MATHML命名空间和SVG名称空间只是元素。

Your directive is treated as void element. Foreign elements are just elements from the MathML namespace and the SVG namespace.

这篇关于指令不被呼吁元素和结束标记,但对自闭工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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