0.0.31 • Published 6 years ago
ng2-yii2-rest v0.0.31
Angular Yii2 REST
This module included two basic classes.
In this example we have an endpoint "/api/v1/users" which returns registered users on the server.
- The first helps build a simple model which get populated by the second service class.
import {BaseModel} from "ng2-yii2-rest";
export class UserModel extends BaseModel {
}
The second is used to be extended by services. It requires three methods to be implemented and the angular http class injected.
import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
import {EndPointService} from "ng2-yii2-rest";
import {User} from "./user.model";
@Injectable()
export class UserService extends EndPointService {
constructor(public http: Http) {
super();
}
public endPointUrl(): string {
return "/api/v1/users";
}
public initModel(data) {
return new UserModel(data);
}
public primaryKey(): string {
return "id";
}
}
This allows us to consume the api is a nice easy way.
import {Component} from "@angular/core";
import {UserService} from "./user.service";
@Component({
moduleId: module.id,
selector: "c-user-list",
templateUrl: "users.component.html",
providers: [UserService]
})
export class UsersComponent {
public users: Array<UserModel>;
constructor(userService: UserService) {
this.userService
.fetchAll()
.subscribe(
(data) => {
this.users = data.payload;
},
(err) => {
console.error(err);
}
);
}
}
0.0.31
6 years ago
0.0.30
6 years ago
0.0.29
6 years ago
0.0.28
6 years ago
0.0.27
6 years ago
0.0.26
7 years ago
0.0.25
7 years ago
0.0.23
7 years ago
0.0.22
7 years ago
0.0.21
7 years ago
0.0.20
7 years ago
0.0.19
7 years ago
0.0.18
7 years ago
0.0.17
7 years ago
0.0.16
7 years ago
0.0.15
7 years ago
0.0.14
7 years ago
0.0.13
7 years ago
0.0.12
7 years ago
0.0.11
7 years ago
0.0.10
7 years ago
0.0.9
7 years ago
0.0.8
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.5
7 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago