如何在角度4的<select2>标记中显示占位符?

时间:2018-07-26 08:50:20

标签: angular jquery-select2 placeholder

我的HTML代码是

<select2 [value]="student" (valueChanged)="studentvaluechanged($event)" [data]="data.getStudentList()"id="student" name="student" 
placeholder="Student Name*">
</select2>

2 个答案:

答案 0 :(得分:0)

使用jQuery

   $("#student").select2({
        placeholder: "Student Name*",
        allowClear: true
    });

或者您可以尝试

<select2 [value]="student" (valueChanged)="studentvaluechanged($event)" [data]="data.getStudentList()"id="student" name="student">Student Name*</select2>

答案 1 :(得分:-1)

我找到了解决方案。添加[options]="{ placeholder: 'Student Name*' }"后,它现在可以使用了。

<select2 [value]="student" (valueChanged)="studentvaluechanged($event)" [data]="data.getStudentList()"id="student" name="student" 
[options]="{ placeholder: 'Student Name*' }">
</select2>