xxxxxxxxxx
>>> ng generate service service_name
or
>>> ng generate service /folder-name/service-name
xxxxxxxxxx
For Creating Service you have type command like below
ng generate service service-name
or
ng g s service-name
And if you want to make service into folder
ng generate service /folder-name/service-name
or
ng g s /folder-name/service-name
xxxxxxxxxx
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TestService {
importantValue:number = 42;
constructor() { }
returnImportantValue(){
return this.importantValue;
}
}
xxxxxxxxxx
ng g s services/data --spec=false
/*
Where:
ng = Angular CLI
g = generate
s = service
services/data = folderWhereTheServiceWillBeCreated/serviceName
--spec=false: Do not create the testing file for the service
*/
xxxxxxxxxx
@Injectable({
providedIn: 'root'
})
export class DataService {
private anime: Anime;
constructor() { }
setAnime(anime: Anime) {
this.anime = anime;
}
getAnime() {
return this.anime;
}
}