简体   繁体   English

object 无效,应为 stream

[英]Invalid object, expected stream

I am getting this error我收到此错误

Type 'never' must have a 'Symbol.iterator' method that returns an iterator.类型 'never' 必须有一个返回迭代器的 'Symbol.iterator' 方法。

I know that error is related to my if statement in the code below (drivers.service.ts)我知道该错误与下面代码中的 if 语句有关(drivers.service.ts)

 export class DriversService { user: User; comp = ''; constructor(private db: AngularFirestore, private auth: AuthService, private afAuth: AngularFireAuth) { } getUsers() { return this.auth.user.pipe( take(1), map(user => { // user['company']; this.comp = user['company']; return user['company']; }) ) } findUser(value) { if(this.comp.length <= 0){ return this.getUsers().subscribe(user => { this.comp = user; console.log('Bye', this.comp) return this.comp; }); } let email = this.db.collection(`companies/${this.comp}/users`, ref => ref.where('email', '==', value)).valueChanges({ idField: 'id' }).pipe( take(1) ); let name = this.db.collection(`companies/${this.comp}/users`, ref => ref.where('name', '==', value)).valueChanges({ idField: 'id' }).pipe( take(1) ); return [email, name]; }

And accutal error is showing in add-driver.page.ts in forkJoin()并且在 forkJoin() 的 add-driver.page.ts 中显示了实际错误

 export class AddDriverPage implements OnInit { users = []; participant = ''; form: FormGroup; constructor(private driverService: DriversService, private loadingCtrl: LoadingController, private auth: AuthService) { } ngOnInit() { } addDriver() { let obs = this.driverService.findUser(this.participant); forkJoin(obs).subscribe(res => { for (let data of res) { if (data.length > 0) { this.users.push(data[0]); } } console.log('it works:', this.participant) this.participant = ''; }); } }

So how do I solve this issue?那么我该如何解决这个问题呢?

Change in your service function:更改您的服务 function:

if (this.comp.length <= 0) {
      return [this.getUsers().pipe(map(user => {
        this.comp = user;
        console.log('Bye', this.comp);
        return this.comp;
       }))];
    }

Then in your component:然后在您的组件中:

addDriver() {
    const obs = this.driverService.findUser(this.participant);

    forkJoin(obs).subscribe(res => {
      if (!res || !res.length) {
        return console.log('Got undefined');
      }
      for (let data of res) {
        if (data.length > 0) {
          this.users.push(data[0]);
        }
      }
      console.log('it works:', this.participant)
      this.participant = '';
    }, error => {
   console.log('Here you got an error: ', error);
});
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'in' 的操作数无效:预期为 Object - Invalid operand to 'in': Object expected 您在需要流的地方提供了一个无效的对象。 你可以提供一个 Observable、Promise、Array 或 Iterable - You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable 元素类型无效:应为字符串 (...) 但得到:对象 - Element type is invalid: expected a string (...) but got: object jQuery JSON发布:传入的对象无效,预期为':'或'}' - jQuery JSON Posting: Invalid object passed in, ':' or '}' expected 警告:propType失败:使用React的类型为`array` expected`object`的prop - Warning: Failed propType: Invalid prop of type `array` expected `object` with React graphQl-参数值无效预期\\“ contentfulStranNaslovQueryString_2 \\”,不是对象 - graphQl - Argument has invalid value Expected \“contentfulStranNaslovQueryString_2\”, found not an object 提供给“BootstrapTable”的“string”类型的无效道具“selectRow”,应为“object” - Invalid prop `selectRow` of type `string` supplied to `BootstrapTable`, expected `object` React - 元素类型无效:需要字符串或类/函数但得到:object - React - Element type is invalid: expected a string or a class/function but got: object 元素类型无效:预期为字符串或类/函数,但得到:对象 - Element type is invalid: expected a string or a class/function but got: object 提供给“路线”的“对象”类型的无效道具“组件”,预期的“功能” - Invalid prop `component` of type `object` supplied to `Route`, expected `function`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM