【发布时间】:2016-07-06 14:13:51
【问题描述】:
我刚开始使用 angular2 materialize 并且 CSS 组件工作正常。但是,当我包含需要初始化的组件(例如选择)时,我不知道如何或在哪里执行此操作。
这是我的表单的 sn-p:
<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();
}
}
【问题讨论】:
标签: typescript angular materialize