gpt4 book ai didi

typescript - 如何初始化 angular2 物化组件?

转载 作者:太空狗 更新时间:2023-10-29 17:47:01 26 4
gpt4 key购买 nike

我刚开始使用 angular2 materialize,CSS 组件工作正常。但是,当我包含一个需要初始化的组件(例如选择)时,我不知道如何或在哪里进行初始化。

这是我的表单的一个片段:

<div class="input-field col s12">
<select>
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Select</label>
</div>

我的组件看起来像这样:

import {Component, ElementRef, Inject, OnInit} from '@angular/core';
import {MaterializeDirective} from "angular2-materialize";

declare var jQuery:any;

@Component({
selector: 'bsi-signup',
styleUrls: ['assets/styles/app.component.css'],
templateUrl: 'assets/templates/signup.component.html',
directives: [MaterializeDirective],
providers: []
})

export class SignupComponent implements OnInit {
elementRef: ElementRef;

constructor(@Inject(ElementRef) elementRef: ElementRef) {
this.elementRef = elementRef;
}

ngOnInit() {
jQuery(this.elementRef.nativeElement).find('select:not([multiple])').material_select();
}
}

最佳答案

添加属性materialize="material_select"

<select materialize="material_select">
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Select</label>

The MaterializeDirective attribute directive (materialize) accepts any MaterializeCSS initialization call to apply to the element. The list of supported functions are provided by MaterializeCSS. Examples: collapsible, leanModal, tooltip, dropdown, tabs, material_select, sideNav, etc.

来源:https://www.npmjs.com/package/angular2-materialize

关于typescript - 如何初始化 angular2 物化组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38226232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com