nhu313 bdb7ddb89a Update 'README.md' | 6 jaren geleden | |
---|---|---|
resources | 6 jaren geleden | |
src | 6 jaren geleden | |
.editorconfig | 6 jaren geleden | |
.gitignore | 6 jaren geleden | |
README.md | 6 jaren geleden | |
config.xml | 6 jaren geleden | |
ionic.config.json | 6 jaren geleden | |
ionic.starter.json | 6 jaren geleden | |
package-lock.json | 6 jaren geleden | |
package.json | 6 jaren geleden | |
tsconfig.json | 6 jaren geleden | |
tslint.json | 6 jaren geleden |
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 this case, I added a provider called api
.
In src/app/app.module.ts
, I did the following:
import { HttpClientModule } from '@angular/common/http';
to the import statement up top.imports
section, I added HttpClientModule
.In src/pages/home/home.ts
, I did the following:
import { ApiProvider } from './../../providers/api/api';
on the top of the fileimport { User } from './../../app/users/user';
on the top of the filepublic apiProvider: ApiProvider
in the constructor methodngOnInit() {
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