@ghostrunners wrote:
I'm following this guide - https://angular.io/docs/ts/latest/guide/server-communication.html - in building an Observable http request to get some data from an [aws public api gateway] url. I can correctly load the
options, but there are 2 problems. 1) I can't get my onChange event to trigger (ui just flickers, never selects the item), and 2) I dont know which life cycle hook should initializesomeItemas a default property (in constructor?) after the options are loaded.private errorMessage: string; **public someItem: any;** public options: any = []; constructor(private myService: ServiceProvider) { } ngOnInit() { this.getSomeOptions(); } getSomeOptions() { var self = this; this.myService.serviceHandler('myKey') .subscribe(data => { self.options = data; self.someItem = data[0]; }, error => this.errorMessage = <any>error); } onChange(e) { this.someRequest.emit(e && e.value); }Here's my DOM -
<ion-segment [(ngModel)]="someItem" (ionChange)="onChange($event)"> <ion-segment-button *ngFor="let item of options" [value]="item"> {{item.label}} </ion-segment-button> </ion-segment>If I set someItem inside the subscribe, the ion-segment defaults to only one option, and I still can't get into my onChange event.
Posts: 4
Participants: 2