CSC360: Another seed, using a web service [3/5] |
Here is an example of the use of services: angular2-seed
Should work for you as before, simply using:
npm install npm start open http://localhost:3000/ in your browser (not automatic)
Interesting bits:
SeedApp
has top-level routes: Home
, About
, RepoBrowser
.
RepoBrowser
has nested routes: RepoList
, RepoDetail
.
GitHub
is an injectable service.
makeRequest
method uses RxJS
Observables, which we will talk about later.
Obervable.map
allows you to transform all of the
values returned by an Observable.
(res) => res.json()
takes a string
and parses it into a json object.
RepoDetail
, Obervable.subscribe
is similar to Promise.then
.
RepoList
, async
calls Obervable.subscribe
.
01 |
<li *ngFor="#repo of repos | async"> <a [routerLink]=" ['RepoDetail', {org: repo.owner.login, name: repo.name}] "> {{ repo.name }} </a> </li> |