I am new to Angular 2 and I hope that I am explaining this ok. I have 3 http paths - 1, 2 & 3. I want to merge/overwrite these. I want path3 to be my default.
If there is a value present in path2, I want this value to overwrite that value in path3 and the same with path1. So, the values in path1 are the most important but if a value is null in path1, the value in path2 then path3 should be used. I have tried using forkJoin
without success.
If a value in path1 or path2 is not present, the pathname rather than the assigned value is being displayed. This is what I have:
export class Loader1 implements Loader2 {
constructor(private http: HttpClient) {
}
public getMethod(lang: string): any {
return Observable.forkjoin(
this.http.get(path1 + '.json').map((res) => res)
.catch((res) => Observable.of(null)),
this.http.get(path2 + '.json').map((res) => res),
this.http.get(path3 + '.json').map((res) => res)
).map(results => {
let emptyCheck = this.http.get(path1 + '.json');
if (emptyCheck.catch((res) => Observable.of(null))) {
results[0] = results[1];
} else {
emptyCheck.map((res) => res);
}
let result = Object.assign({}, results[2], results[1], results[0]);
return result;
});
}
}
path1:
{
"value1": "First number1",
"value5": "First number5",
"value10": "First number10"
}
path2:
{
"value1": "Second number1",
"value2": "Second number2",
"value4": "Second number4",
"value5": "Second number5",
"value6": "Second number6",
"value7": "Second number7",
"value10": "Second number10"
}
path3:
{
"value1": "Third number1",
"value2": "Third number2",
"value3": "Third number3",
"value4": "Third number4",
"value5": "Third number5",
"value6": "Third number6",
"value7": "Third number7",
"value8": "Third number8",
"value9": "Third number9",
"value10": "Third number10"
}
Expected Output:
First number1
Second number2
Third number3
Second number4
First number5
Second number6
Second number7
Third number8
Third number9
First number10
Actual output:
path1.value1
path2.value2
Third number3
path2.value4
path1.value5
path2.value6
path2.value7
Third number8
Third number9
path1.value10