简体   繁体   English

ng-content在select标签Angular2中不起作用

[英]ng-content is not working inside select tag Angular2

i am trying to make a custom dropdown component but when i try to access data through ng-content inside select tag its not working. 我正在尝试制作自定义下拉组件,但当我尝试通过选择标签内的ng-content访问数据时,它无法正常工作。

this is my custom-component html file: 这是我的自定义组件html文件:

<select class="form-control">

    <ng-content></ng-content>

</select>

this is my main html file where i am calling the component: 这是我调用组件的主要html文件:

<dropdown>
        <option value="">Select details type</option>
        <option value="">Personal</option>
        <option value="">General</option>
        <option value="">Contact</option>
        <option value="">Settings</option>
 </dropdown>

what i am doing wrong ??? 我做错了什么???

Currently angular2 uses native (browser) HTML parser. 目前angular2使用本机(浏览器)HTML解析器。 According to the standard only <optgroup> and <option> HTML elements are permitted inside <select> element (see here ). 根据标准,只有<optgroup><option>允许在<select>元素内部使用HTML元素(参见此处 )。 At least Chrome removes all other HTML tags. 至少Chrome会删除所有其他HTML标记。 Try to execute the next code in Chrome: 尝试在Chrome中执行下一个代码:

var div = document.createElement('div');
div.innerHTML = '<select><ng-content></ng-content></select>';
console.log(div.innerHTML) // "<select><select>"

So, at the time angular2 will start to process the markup, <ng-content> will be already removed. 因此,当angular2开始处理标记时, <ng-content>将被删除。

This issue can be resolved after (and if) angular2 team implements its own HTML parser 在(并且如果) angular2团队实现其自己的HTML解析器之后,可以解决此问题

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

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