NativeScript ListView不会显示我的数据

时间:2018-03-22 18:13:23

标签: angular listview nativescript

我是NativeScript的新手,决定用它做一个基本的应用......所以我用HttpClient创建一个服务......无论如何,当我做console.dir(事件)时,数据显示在控制台中,当我使用标签时,它也会显示,但它不会在我的ListView中显示  这是我的模板:

    <StackLayout class="page">
    <ListView [items]="events" class="list-group">
        <ng-template let-item="item">
            <Label [text]="item.theme"
                   class="list-group-item"></Label>
        </ng-template>
    </ListView>
</StackLayout>

我的同意有这个:

    constructor(private eventService: EventService) { }

      ngOnInit() {
        this.getEvents();
      }


        getEvents(){
            this.eventService.loadEvents().subscribe(
                data => {
                    this.events = {...data};
                    console.dir(this.events)
                },
                error => this.error = error
            );
        }

我的服务是:

constructor( private http: HttpClient ) {}

    loadEvents(){
        return this.http.get<Event>(this.baseUrl)
            .pipe(
                retry(3),
                catchError(this.handleError)
            );

    }

    private handleError(error: HttpErrorResponse) {
        if (error.error instanceof ErrorEvent) {
            // A client-side or network error occurred. Handle it accordingly.
            console.error('An error occurred:', error.error.message);
        } else {
            // The backend returned an unsuccessful response code.
            // The response body may contain clues as to what went wrong,
            console.error(
                `Backend returned code ${error.status}, ` +
                `body was: ${error.error}`);
        }
        // return an ErrorObservable with a user-facing error message
        return new ErrorObservable(
            'Something bad happened; please try again later.');
    };

我真的很感激帮助...提前致谢

0 个答案:

没有答案