私はSELECT2を動作するようになった方法を見てみましょう。
乾杯私のスコープでscssを使ってスタイルを設定してください。
HTML:ngAfterViewInit
上の活字体で
<select multiple="multiple" style="display: none;">
<option *ngFor="#item of people" [value]="item.id">
{{item.name}}
</option>
</select>
INIT:
ngAfterViewInit()
{
var element = (<any>$('select')).select2().siblings('.select2-container')[0];
var attribute = ObjectHelper.setElementContentAttribute(this.m_elementRef.nativeElement, element, true);
}
や特別な魔法の機能でお子様に_ngcontent
属性のクローンを作成します。いくつかの動的コンテンツが生成される第三者図書館では、非常に便利です。
public static getAngularElementTag(element: Element): string
{
var attrs = [].filter.call(element.attributes, at => /^_nghost-/.test(at.name));
if (attrs.length == 0)
{
return null;
}
return attrs[0].name.replace("_nghost-", "_ngcontent-");
}
public static setElementContentAttribute(hostElement: Element, targetElement: Element, setRecursive?: boolean): string
{
var attribute = this.getAngularElementTag(hostElement);
setRecursive = (setRecursive !== undefined) ? setRecursive : false;
if (attribute !== null)
{
this._setElementContentAttribute(targetElement, setRecursive, attribute);
return attribute;
}
else
{
return null;
}
}
private static _setElementContentAttribute(targetElement: Element, recursive: boolean, attribute) {
targetElement.setAttribute(attribute, '');
if (recursive) {
for (var i = 0; i < targetElement.childElementCount; i++) {
this._setElementContentAttribute(<Element>targetElement.childNodes[i], recursive, attribute);
}
}
}
入力要素をスタイルするだけです。動的に追加された要素(セレクション、セレクター)の場合、イベントの一部を捕まえて再度魔法を実行する必要があります。
最後に解決策を見つけましたか? – Shahin