我在这一点上遇到了这个错误,希望你们中的一些专家可以帮助我。在添加搜索栏之前,我的网站正常工作(只是一个了解更多有关Angular的项目(,我不知道我确实尝试搜索App.模块错误,但我看不到任何问题。
欢呼!
未接收错误:意外的值'searchservicemodule'由模块" appModule"声明。请添加@pipe/@directive/@组件注释
**My app.module.ts looks like this**
enter code here
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { MovielistComponent } from './movielist/movielist.component';
import { SearchserviceModule } from './searchservice/searchservice.module';
@NgModule({
declarations: [
AppComponent,
MovielistComponent,
SearchserviceModule,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([
{
path: 'movielist',
component: MovielistComponent
},
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
**My app.component.ts looks like this**
import { Component } from '@angular/core';
import { Http, Response} from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { SearchserviceModule } from './searchservice/searchservice.module';
import { Subject } from 'rxjs/Subject';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [SearchserviceModule]
})
export class AppComponent {
results: Object;
searchTerm$ = new Subject<string>();
constructor(private searchService: SearchserviceModule) {
this.searchService.search(this.searchTerm$)
.subscribe(results => {
this.results = results.results;
});
}
}
**My searchservice.module.ts looks like this**
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/switchMap';
@Injectable()
export class SearchserviceModule {
baseUrl: string = 'https://api.cdnjs.com/libraries';
queryUrl: string = '?search=';
constructor(private http: Http) { }
search(terms: Observable<string>) {
return terms.debounceTime(400)
.distinctUntilChanged()
.switchMap(term => this.searchEntries(term));
}
searchEntries(term) {
return this.http
.get(this.baseUrl + this.queryUrl + term)
.map(res => res.json());
}
}
向不声明的提供商添加searchServiceModule:
@NgModule({
declarations: [
AppComponent,
MovielistComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([
{
path: 'movielist',
component: MovielistComponent
},
])
],
providers: [SearchserviceModule],
bootstrap: [AppComponent]
})
export class AppModule { }