0.0.31 • Published 7 years ago

ng2-yii2-rest v0.0.31

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

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

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

8 years ago

0.0.25

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago