简体   繁体   English

css:empty,:空白,里面有注释

[英]css :empty, :blank with comment inside

我正在使用:空和:空白,它们工作正常,但我有一个案例,其中角度是在div中注入注释,那些将不再工作,在这种情况下我可以做的事情是这样的:空和:空白将工作有评论?

There are few things that you can do... try to have a look at: https://docs.angularjs.org/guide/production paying attention to the $compileProvider.debugInfoEnabled(false); 你可以做的事情很少......试着看看: https$compileProvider.debugInfoEnabled(false);注意$compileProvider.debugInfoEnabled(false); ... ...

Generally is not a good idea the use of :empty (or something else) pseudoselector with the goal of selecting empty elements because that selectors are sensible to everything, whitespace included. 通常不是一个好主意使用:empty (或其他)伪选择,目的是选择空元素,因为选择器对所有内容都是敏感的,包括空格。 There is an example: 有一个例子:

 div { width: 30px; height: 30px; background: cyan; margin: 5px; } div:empty { display: none; } 
 <div> </div> <div> </div> <!-- just this --> <div></div> 

EDITED EDITED

a possible workaround could be creating a custom directive that does this for you, but, of course, it should be manually added to the elements where you want to know if they are empty or not. 一个可能的解决方法可能是创建一个为您执行此操作的自定义指令,但是,当然,它应该手动添加到您想知道它们是否为空的元素。 Here is an example: 这是一个例子:

 angular .module('test', []) .directive('emptyClass', function() { return function postLink(iScope, iElement, iAttrs) { function updateOnChanges() { var classname = iAttrs.emptyClass; var hasContent = iElement.children().length > 0 || iElement.text().trim().length > 0; if(hasContent) { return iElement.removeClass(classname); } return iElement.addClass(classname); } iElement[0].addEventListener( "DOMSubtreeModified", updateOnChanges, false ); updateOnChanges(); } }) ; 
 .is-empty { background: cyan; display: block; min-height: 20px; margin: 10px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <section ng-app="test"> <h1 empty-class="is-empty"> </h1> <h1 empty-class="is-empty"></h1> <h1 empty-class="is-empty"> <!-- ng-if: "oh Yeah" --> </h1> <h1 empty-class="is-empty"> Hello World </h1> <h1 empty-class="is-empty"><span>Hello World</span></h1> </section> 

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

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