type'可观察< void>'无法分配到type'可观察的boolean>'

发布于 2025-01-19 00:04:25 字数 2254 浏览 1 评论 0原文

知道该怎么办

不 它一直告诉我 类型“可观察”不能分配给“可观察到的”。 键入“ void”不可分配给“布尔值”。

但是,当我将其更改为无效时,它也不适用

于不良英语的不良英语,

这是代码的

import { Component, OnDestroy , OnInit  } from '@angular/core';
import { AuthsService } from '../auths.service';
import { FormBuilder,FormGroup,Validators } from '@angular/forms';
import { UiService } from 'src/app/shared/ui.service';
import { Subscription,Observable, map } from 'rxjs';
import { select, Store } from '@ngrx/store';

import * as fromRoot from '../../app.reducer';
import * as fromLoading from '../../shared/load.reducer'

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {

  loginForm!: FormGroup;

  constructor(private Authservice: AuthsService, private fb: FormBuilder, private uiService: UiService,
    private Stoore: Store<{ui:fromLoading.State}>
  ) { }
  private loadingSub: Subscription;
  
  isloading$:  Observable<boolean>;

  ngOnInit(): void {

    this.isloading$ = this.Stoore.pipe(map(state => { state.ui.theLoading }));
                                

    this.loginForm = this.fb.group({
      email: ['', Validators.required],
      password:['',Validators.required]
    })

  }

  
  


  onSubmit() {
    this.Authservice.login({
      email:this.loginForm.value.email,
      password:this.loginForm.value.password
    })
  }
}

REDUCER代码,

export interface State {
   theLoading: boolean;
}

const initialState: State = {
   theLoading:false
}

export function LoadingReducer(state = initialState, action) {
   switch (action.type) {
      case 'START_LOADING':
         return {
            theLoading: true,
         }
      
      case 'STOP_LOADING':
         return {
            theLoading:false
         }
      
      default :
         return {
            state
         }
   }
}

我想将其存储在

this.isloading $ = this.stoore.pipe(Map(state =&gt; {state state)。 ui.theloading}));

但是它一直告诉我

TS2322: Type 'Observable<void>' is not assignable to type 'Observable<boolean>'.
  Type 'void' is not assignable to type 'boolean'.

I do not know what should i do can anyone help me please

I made the reducer and added the cases

but my problem is when I connect the reducer with the observable
it keep telling me
Type 'Observable' is not assignable to type 'Observable'.
Type 'void' is not assignable to type 'boolean'.

but when i changed it to void it dose not also work

sorry for the bad english

here is the code

import { Component, OnDestroy , OnInit  } from '@angular/core';
import { AuthsService } from '../auths.service';
import { FormBuilder,FormGroup,Validators } from '@angular/forms';
import { UiService } from 'src/app/shared/ui.service';
import { Subscription,Observable, map } from 'rxjs';
import { select, Store } from '@ngrx/store';

import * as fromRoot from '../../app.reducer';
import * as fromLoading from '../../shared/load.reducer'

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {

  loginForm!: FormGroup;

  constructor(private Authservice: AuthsService, private fb: FormBuilder, private uiService: UiService,
    private Stoore: Store<{ui:fromLoading.State}>
  ) { }
  private loadingSub: Subscription;
  
  isloading$:  Observable<boolean>;

  ngOnInit(): void {

    this.isloading$ = this.Stoore.pipe(map(state => { state.ui.theLoading }));
                                

    this.loginForm = this.fb.group({
      email: ['', Validators.required],
      password:['',Validators.required]
    })

  }

  
  


  onSubmit() {
    this.Authservice.login({
      email:this.loginForm.value.email,
      password:this.loginForm.value.password
    })
  }
}

the reducer code

export interface State {
   theLoading: boolean;
}

const initialState: State = {
   theLoading:false
}

export function LoadingReducer(state = initialState, action) {
   switch (action.type) {
      case 'START_LOADING':
         return {
            theLoading: true,
         }
      
      case 'STOP_LOADING':
         return {
            theLoading:false
         }
      
      default :
         return {
            state
         }
   }
}

I want to store it in

this.isloading$ = this.Stoore.pipe(map(state => { state.ui.theLoading }));

but it keep telling me

TS2322: Type 'Observable<void>' is not assignable to type 'Observable<boolean>'.
  Type 'void' is not assignable to type 'boolean'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文