Looking to extract the id parameter from the route, fetch the corresponding task, and then its parent if applicable.
Angular CLI: 7.1.4
Node: 11.6.0
OS: linux x64
Angular: 7.1.4
@angular-devkit/architect 0.11.4
@angular-devkit/build-angular 0.11.4
@angular-devkit/build-optimizer 0.11.4
Task service:
import { ITask } from '@task/interfaces/task';
...
export class TaskService {
constructor(private _http: HttpClient) {}
...
get_task(id: number) {
return this._http.get<ITask>(\`http://127.0.0.1:8000/api/task/${id}\`);
}
In my component:
Obtaining one task that already has 2 subscriptions
this._route.params.subscribe((params: Params) => {
this._task_service
.get_task(params['id'])
.subscribe(
(data: ITask) => { this.task = data; },
err => { this._log.log('error while fetching task ', err); }
);
});
I want to
this._route.params
get_task(params['id'])
if `task.parent` get parent task
After hours of research and multiple failed attempts
flatMap().subscribe(...)
// Type 'Subscription' is not assignable to type 'ObservableInput<{}>'
Despite reading numerous posts online, I'm still confused.
Can someone provide an explanation and example on how to achieve this?
update
console.log(
'type ',
typeof this._task_service.get_task(2),
this._task_service.get_task(2)
);
Result obtained:
type object
{…}
_isScalar: false
operator: {…}
project: function request()
thisArg: undefined
__proto__: Object { call: call(), … }
source: {…}
_isScalar: false
operator: {…}
predicate: function
./node_modules/@angular/common/fesm5/http.js/HttpClient.prototype.request/res$<()
thisArg: undefined
__proto__: Object { call: call(), … }
source: Object { _isScalar: false, source: {…}, operator: {…} }
__proto__: Object { lift: lift(), subscribe: subscribe(), _trySubscribe:
d_trySubscribe(), … }
__proto__: Object { lift: lift(), subscribe: subscribe(), _trySubscribe: _trySubscribe(), … }