I'm trying to simply display a checkbox in a bootstrap drop down but its just displays as blank. It's a generic dropdown. Below I've shown my code and a few screenshots. I feel like this is kinda bizarre and not sure if this is an angular thing or not.
stackblitz url:
https://stackblitz.com/edit/angular-45uk59
Code:
<div class="form-group">
<label *ngIf='label!=null' for={{id}}>{{label}}}</label>
<select class="form-control" id="{{id}}">
<option value="-1"></option>
<option *ngFor="let item of content; let i = index" value="{{item.value}}">
<span *ngIf='hasCheckbox === true'>
<!-- <input type="checkbox" id="{{id}}_i" />   -->
<input type="checkbox" name="item.text[{{i}}]" value="{{item.value}}" />
</span>
{{item.text}}
</option>
</select>
</div>
Component:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'dropdown',
templateUrl: './dropdown.component.html',
styleUrls: ['./dropdown.component.scss']
})
export class DropdownComponent implements OnInit {
content: DropDownContent[] = new Array<DropDownContent>();
@Input() hasCheckbox:boolean = false;
@Input() label:string = null;
@Input() id:string = 'defaultId'
@Input() selectedId:number = -1;
@Input() size: 'lg' | 'md' | 'sm' = 'lg';
@Input() set contentInput(contentInput: DropDownContent[]) {
if (contentInput) {
this.content = contentInput.map(data => {
return <DropDownContent>(data);
});
console.log(this.content);
} else {
//?
}
}
constructor() { }
ngOnInit() {
console.log(this.id)
}
}
export class DropDownContent {
value: number;
text: string;
}