I
I
Ivan Stroykin2017-04-06 15:30:13
Angular
Ivan Stroykin, 2017-04-06 15:30:13

How to take all options from select if options are passed to ng-content?

Good day,
There is a component

<select #select>
  <ng-content></ng-content>
</select>

This is necessary, because further there is a lot of logic that does not play a role in this context.
When we pass an option list to ng-content, I can't take all the options as an array
...
@ViewChild('select') select: ElementRef;

ngOnInit() {
  console.log(this.select.nativeElement.params);
}

Gives undefined, although the list is there. If you arrange without ng-content, then everything is taken well

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ozknemoy, 2017-04-07
@StivinKing

often ngOnInit () does not have time to pick up the data. especially if they come from the server. but ngOnChanges picks up everything. I'm not sure about ViewChild, I don't use it, but @Input will work exactly
@Input select;
ngOnChanges() {
console.log(this.select);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question