I am experimenting with the nb-stepper
component, and would like to set the selectedIndex
in my angular component. When specifying two-way binding on [(selectedIndex)]
after refreshing my activities, the nb-step is not updated to show the selected step.
In my component, I have added an Input() for selectedActivityIndex, which updates the nb-stepper
if I set this value in ngOnInit()
. But later, after getting a new list of activities, I seem unable to inform the stepper of a new selectedIndex
.
activities.html
<nb-stepper orientation="vertical" disableStepNavigation="true" [(selectedIndex)]="selectedActivityIndex">
<nb-step *ngFor="let activity of activities"
[label]="activity.name"
[completed]="activity.completed"
></nb-step>
</nb-stepper>
activities.component.ts
export class ActivitiesComponent {
private _selectedActivityIndex: number;
@Output() onSelectedActivityIndexChange = new EventEmitter();
@Input()
get selectedActivityIndex() {
return this._selectedActivityIndex;
}
set selectedActivityIndex(val) {
this._selectedActivityIndex = val;
this.onSelectedActivityIndexChange.emit(this.selectedActivityIndex);
}
constructor(private activitiesService: ActivitiesService) {
this.activities = []
}
ngOnInit() {
this.selectedActivityIndex = 0
this.activitiesService.getActivities()
.subscribe(data => {
if(data['statusCode'] == 200) {
this.activities = data['activities'];
this.selectedActivityIndex = this.activities.map(m => { return m.selected; }).indexOf(true, 0)
}
else
console.log('Failure to get activities: ' + data['statusCode'])
});
}
I would expect the selectedIndex
to be updated to the value specified in the JSON response returned by the service, in fact even setting this.selectedActivityIndex = 1
in subscribe does not work.