Nhu Nguyen 824a0d721d added provider api 6 gadus atpakaļ
resources init 6 gadus atpakaļ
src added provider api 6 gadus atpakaļ
.editorconfig init 6 gadus atpakaļ
.gitignore init 6 gadus atpakaļ
README.md added provider api 6 gadus atpakaļ
config.xml init 6 gadus atpakaļ
ionic.config.json init 6 gadus atpakaļ
ionic.starter.json init 6 gadus atpakaļ
package-lock.json added provider api 6 gadus atpakaļ
package.json added provider api 6 gadus atpakaļ
tsconfig.json init 6 gadus atpakaļ
tslint.json init 6 gadus atpakaļ

README.md

This is a simple ionic app to show you how to use provider to make request to the server.

You can generate your own provider with the command

ionic g provider [providername]

This will create a providers/[providername]/[providername].ts file. In that file you will make the call to your server. You can read Accessing Rest With Angular blog post to learn more.

In src/app/app.module.ts, I added import { HttpClientModule } from '@angular/common/http'; to the import statement up top. Then in the imports section, I added HttpClientModule.

In src/pages/home/home.ts, I did the following:

  1. added import { ApiProvider } from './../../providers/api/api'; on the top of the file
  2. added import { User } from './../../app/users/user'; on the top of the file
  3. injected in the public apiProvider: ApiProvider in the constructor method
  4. Added these two methods to tell the app to make the call to the server when it's initialized:
ngOnInit() {
  this.loadUsers();
}

loadUsers() {
  this.apiProvider.getUsers().subscribe(
    data => this.users = data["_embedded"]["users"],
    err => {
        console.log(err);
    });
}

https://ionicacademy.com/http-calls-ionic/ https://scotch.io/tutorials/angular-2-http-requests-with-observables