小编Gho*_*med的帖子

仅当第一次失败时才执行第二次 http 调用

尝试通过管道传输两个 Angular http 调用,仅当第一个调用失败时才执行第二个调用。

第一个电话是:

 return this.http.get<AssetGroupHistoryResponseModel>('./assets/data.json');
Run Code Online (Sandbox Code Playgroud)

如果 data.json 不存在,则会引发 404 Not Found 错误,它应该调用适当的 API:

return this.http.get<AssetGroupHistoryResponseModel>(url);
Run Code Online (Sandbox Code Playgroud)

不知道如何使用 rxjs 获得这种行为。

http reactive-programming rxjs angular

3
推荐指数
1
解决办法
1039
查看次数

搜索单词是否在数组内

我有这个脚本,想让它搜索数组中是否只有Mango这个单词,如果它是true console.log它的索引。

我已经尝试过下面的代码,但是它总是失败(假)。

<!DOCTYPE html>
<html>

<body>
    <h1>Array includes()</h1>
    <p>Check if the fruit array contains "Mango":</p>
    <p id="demo"></p>
    <p><strong>Note:</strong> The includes method is not supported in Edge 13 (and earlier versions).</p>
    <script>
        var fruits = ["Banana is yellow", "Orange juice", "Apple is red", "Mango is orange"];
        var n = fruits.includes("Mango");
        console.log(n);
    </script>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

我需要它返回它所在的索引= 4

javascript

2
推荐指数
1
解决办法
85
查看次数

标签 统计

angular ×1

http ×1

javascript ×1

reactive-programming ×1

rxjs ×1