i Select2 çalışmak lazım bakalım.
Alkış benim kapsamımda scss ile onları stil. ngAfterViewInit
daktilo harfleri ile
<select multiple="multiple" style="display: none;">
<option *ngFor="#item of people" [value]="item.id">
{{item.name}}
</option>
</select>
Init:
Html
ngAfterViewInit()
{
var element = (<any>$('select')).select2().siblings('.select2-container')[0];
var attribute = ObjectHelper.setElementContentAttribute(this.m_elementRef.nativeElement, element, true);
}
Ve özel sihirli işlevleri oğul _ngcontent
niteliğini klonlamak. Bazı dinamik içerik oluşturulur 3. parti kütüphaneleri, bir sürü için çok yararlıdır:
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);
}
}
}
Sadece giriş elemanı stil yapılmış. Dinamik olarak eklenen elemanlar (seçimler, seçici) için muhtemelen bazı olayları yakalamanız ve sihri tekrar yapmanız gerekir.
Bunun için bir çözüm buldunuz mu? – Shahin