尝试从 5 升级到 Angular 6 并收到此错误:
src/app/app.component.ts(26,23) 中的错误:错误 TS2339:“Observable”类型上不存在“distinctUntilChanged”属性。
我在 app.module.ts 中导入了 distinctUntilChanged:
import "rxjs/add/operator/distinctUntilChanged";
Run Code Online (Sandbox Code Playgroud)
我在 app.component.ts 中的代码:
import { Component } from "@angular/core"; import { Router, NavigationEnd } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { GeoService } from "app/services/geo.service";
import { ArbeteService } from "app/services/arbete.service";
import { GoogleAnalyticsEventsService } from "app/services/google-analytics-events.service";
import * as _ from "lodash";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent {
//Send pageview to Google Analytics
router.events.distinctUntilChanged((previous: any, …Run Code Online (Sandbox Code Playgroud) enter code here
getHospital(term: string = null): Observable<Hospitals[]> {
let items = this.getHospitals1();
if (term) {
items = items.filter(x => x.name.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1);
}
return items.pipe(delay(500));;
}
getHospitals1() : Observable<Hospitals[]>{
return this.http.get<Hospitals[]>('https://my-json-server.typicode.com/monsterbrain/FakeJsonServer/hospitals')
}
Run Code Online (Sandbox Code Playgroud)
当我添加过滤器时发生错误 这是使用 ng-select 的下拉列表的代码。它基于基于文本的搜索,这里使用 angular7 和 rxjs 6
我有一个动作,我想用它来初始化我的应用程序,我想为这个动作创建一个史诗,然后在这个动作的后面触发多个其他动作,等待它们全部完成,然后再触发另一个动作。我看了一下别人的质疑,这是非常类似于这样一个
我已经尝试过这种方法,但对我来说,它不起作用,它会触发该APP_INIT动作,但随后无法触发序列中的任何其他动作。有人可以帮忙吗?
import { of } from 'rxjs';
import { mergeMap, zip, concat, mapTo } from 'rxjs/operators';
import { ofType } from 'redux-observable';
import { firstAction, secondAction } from 'actions';
export default function appInit (action$) {
return (
action$.pipe(
ofType('APP_INIT'),
mergeMap(() =>
concat(
of(firstAction()),
of(secondAction()),
zip(
action$.ofType('ACTION_ONE_COMPLETE'),
action$.ofType('ACTION_TWO_COMPLETE')
).mapTo(() => console.log('complete'))
)
)
)
);
}
Run Code Online (Sandbox Code Playgroud) 我正在从 swagger pets API 中获取宠物列表。我想删除具有重复 id 的宠物,然后将其发送到 React 以避免重复密钥问题。我尝试了下面的代码,但对我不起作用。谁能帮我解决这个问题?
我是 RxJS 的新手,所以想删除基于宠物 ID 过滤不同对象的注释代码。
export function fetchPetEpic(action$) {
return action$.pipe(
ofType('GET_PETS'),
switchMap(action =>
ajax.getJSON(`https://petstore.swagger.io/v2/pet/findByStatus?status=${action.payload}`).pipe(
map( response => response.map( (pet) => ({
id: pet.id,
pet: pet.pet
}))),
distinct( petList => petList.id),
// map( petList => petList.filter((pet, index, list) => {
// return list.map(petObj =>
// petObj.id).indexOf(pet.id) === index;
// })),
map(response => petActions.setPets(response))
)),
catchError( error => ({ type: 'ERROR_PETS_FETCH', payload: error})),
)
}
Run Code Online (Sandbox Code Playgroud)
假设 pets 数组类似于 [ { id: 1, …
我将开始在 Angular 6+ 中使用 RXJS 和套接字 io,但在此之前我想知道这两者是否相同或不同。有人可以帮助我在 Angular 中使用它们吗?
我试图实现具有使用数据流内观测,在这里我用一个从mergeMap,concatMap等等。
例如:
const output$$ = input$$.pipe(
mergeMap(str => of(str).pipe(delay(10))),
share()
);
output$$.subscribe(console.log);
Run Code Online (Sandbox Code Playgroud)
这在登录控制台时工作正常。但是,当我尝试用它做出反应像下面利用useEffect和useState挂钩更新一些文字:
function App() {
const input$ = new Subject<string>();
const input$$ = input$.pipe(share());
const output$$ = input$$.pipe(
mergeMap(str => of(str).pipe(delay(10))),
share()
);
output$$.subscribe(console.log);
// This works
const [input, setInput] = useState("");
const [output, setOutput] = useState("");
useEffect(() => {
const subscription = input$$.subscribe(setInput);
return () => {
subscription.unsubscribe();
};
}, [input$$]);
useEffect(() => {
const subscription = output$$.subscribe(setOutput); …Run Code Online (Sandbox Code Playgroud) 我订阅了从 NgRx 减速器获取提供程序的订阅。takeUntil()当最终返回一个包含内容的数组时,我想使用它来自动关闭订阅:
// Fetch providers
this.store.pipe(select(reducer.getProviders))
// .takeUntil(reducer.getProviders.length > 0)
.subscribe(providers => {
if (providers) {
this.providers = providers;
// takeUntil(/** something **/);
}
});
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄这个吗?
我不知道如何利用 takeUntil()
例如 :
这里有一个重现: https: //github.com/valeriob/Repro_rxjs_typescript 只需运行“tsc”并查看编译错误。
在这种情况下编辑index.ts时如何获取类型定义?
遵循这些指南https://github.com/zspitz/TypeScript-Handbook/blob/release-2.0/pages/Modules.md#umd-modules 我能够通过附加“导出为命名空间 rxjs;”来使其工作;到文件 node_modules/rxjs/index.d.ts 。
如果这应该是解决方案,那么它应该由库作者完成吗?
source<http>
.pipe(
switchMap(d => this.http.get(d))
.pipe(
switchMap(j => this.http.get(j))
)
)
.subscribe()
Run Code Online (Sandbox Code Playgroud)
您好,我需要连续发出 3 个 http 请求,其中每个调用都包含下一次调用的数据。嵌套切换映射是这种情况下的最佳实践吗?
我最近将应用程序更新为angular 6,将RxJs更新为6.3.3 version。
如描述在这里,我使用的包rxjs-compat有暂时写入RxJS5和RxJS6兼容模式的代码,在相同的时间。
正如RxJS团队所建议的那样,在更新所有代码以使其与RxJS6兼容之后,我将rxjs-compat其卸载了,因为不再需要它了。
在那之后,我试图运行我的代码,但是编译器正在检索以下错误:
node_modules / rxjs / Rx.d.ts(1,15)中的错误:错误TS2307:找不到模块“ rxjs-compat”
有人知道这里可能有什么问题吗?这似乎取决于RxJS的方式rxjs-compat,但是如果我说的是真的,为什么RxJS团队建议卸载rxjs-compat?
rxjs6 ×10
rxjs ×6
angular ×5
angular6 ×3
javascript ×2
rxjs5 ×2
typescript ×2
angular5 ×1
ngrx ×1
ngrx-store ×1
react-hooks ×1
reactjs ×1
redux ×1
socket.io ×1
umd ×1