I've encountered a challenge while trying to make Feathers work in Angular with a Feathers REST server. It seems that no requests are being made.
My Feathers server hosts the resource http://example.com/app/experiences which returns data in paginated Feathers format:
{
"total": 1,
"limit": 10,
"skip": 0,
"data": [
{
"_id": "5db5ef8dc64f59001d750c72",
... etc ..,
}
]
On the client side, I have a centralized Feathers service configuration:
@Injectable()
export class Feathers {
private _feathers = feathers();
private feathersRestClient = feathersRestClient('http://example.com/app');
constructor() {
this._feathers
.configure(this.feathersRestClient.angular)
.configure(rx({
idField: '_id'
}));
this._feathers.use('/experiences', new FeathersGenericService());
}
// expose services
public service(name: string) {
return this._feathers.service(name);
}
}
The FeathersGenericService is a generic class obtained from :
export class FeathersGenericService implements ServiceMethods<any> {
async find(params: Params) {}
async get(id: Id, params: Params) {}
async create(data: any, params: Params) {}
async update(id: NullableId, data: any, params: Params) {}
async patch(id: NullableId, data: any, params: Params) {}
async remove(id: NullableId, params: Params) {}
}
Next, I have a simple ExperienceService that retrieves the first 25 results:
export class ExperienceService {
constructor(private feathers: Feathers) { }
experiences$() {
return from((this.feathers
.service('experiences'))
.watch()
.find({
query: {
$limit: 25
}
}));
}
}
And lastly, the component:
export class ExperienceListComponent implements OnInit {
experiences$: Observable<any[]>;
constructor(private eservice: ExperienceService) {}
ngOnInit() {
this.eservice.experiences$().subscribe(res => {
console.log(res);
return res;
});
}
}
However, the variable "res" turns out to be undefined... I checked the network tab and noticed that no request was sent to the API.
What could I possibly be doing wrong?
EDIT: I've created a Stackblitz demo here: https://stackblitz.com/edit/angular-qfysld
There's a known bug with using Feathers in Stackblitz, making it fail to compile there but works fine when downloaded and run locally.