Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70769

Loading Controllers with APIs and Observables

$
0
0

@karvanj wrote:

Hi all, in my mission to embrace observables and extension from this post, I am writing to see how everyone would go about implementing a loading controller on fetch.

As a working example say I have an API fetch users in a service.

export class UserService {

    constructor(
        public http: Http
    ) {}

    public fetchUsers() {
        return this.http.get("/api/users").map((res: Response) => res.json())
    }
}

In my component page I have an observable that fetches new users on init.

export class UserList {

    public users$: Observable<Users[]>

    constructor(
        public userService: UserService,
    ) 
    public ngOnInit() {
        this.users$ = this.userService.fetchUsers()
    }



}

The question I am asking how would you implement a loading controller(ie a spinner wheel saying it’s loading) to start when fetching users begins. And then dismissed once completed. Is it possible using the observable method?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70769

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>