尝试使用ng-select但出现错误

时间:2018-10-11 09:50:27

标签: angular angular6

我最近学习了angular-6,现在我正在尝试使用ng-select https://github.com/ng-select/ng-select。但是我得到一个错误

  src / app / subject.service.ts(20,27)中的

ERROR:错误TS2339:属性   “可观察”类型不存在“过滤器”。

这是我的subject.service.ts

import { Injectable } from '@angular/core';
    import { Course } from './course'
    import { CourseService } from  './course.service';
    import { HttpClient, HttpHeaders, HttpEventType, HttpRequest, HttpErrorResponse, HttpEvent } from '@angular/common/http';
    import { Observable, asapScheduler, pipe, of, from,interval, merge, fromEvent } from 'rxjs';
    import { filter ,delay, map } from 'rxjs/operators';

    @Injectable({
      providedIn: 'root'
    })

    export class SubjectService {

      constructor(private c_service:CourseService, private http:HttpClient) { }

      getCourse(term: string = null): Observable<Course[]> {
           let items = this.requestCourse();
           console.log(items);
             if (term) {
                items = items.filter(x => x.CourseId.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1);
            }
            return (items).pipe(delay(500));
        }

        requestCourse() {
          return  this.http.get<any>(`http://192.168.3.223:84/elearningapi/course_api.php?request=1`);
        }
    }

从这个请求http://192.168.3.223:84/elearningapi/course_api.php?request=1我得到了

[  
   {  
      "CourseId":"C002",
      "CourseDescription":"Javascript"
   },
   {  
      "CourseId":"C003",
      "CourseDescription":"Math"
   },
   {  
      "CourseId":"C004",
      "CourseDescription":"English Language"
   },
   {  
      "CourseId":"C005",
      "CourseDescription":"IPS"
   },
   {  
      "CourseId":"C006",
      "CourseDescription":"IPA"
   },
   {  
      "CourseId":"C007",
      "CourseDescription":"C#"
   }
]

我该如何解决?预先感谢

1 个答案:

答案 0 :(得分:0)

RxJ改变了版本6中将运算符链接在一起的方式。在新版本中,您在使用运算符之前先映射(例如)map和filter,然后像这样:

items = items.pipe(filter(x => x.CourseId.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1));