我正在学习使用Angular 4,并且在努力学习中,我想安装PrimeNG的Autocomplete元素并出现以下错误:
我的项目很基本,我有以下内容:
autocomplete.component.ts
import { AutoCompleteModule } from 'primeng/primeng';
import { Component, OnInit } from '@angular/core';
import { AutocompleteService } from '../../servicios/autocomplete.service';
@Component({
selector: 'app-autocomplete',
templateUrl: './autocomplete.component.html'
})
export class AutocompleteComponent implements OnInit {
text: string;
results: string[];
search(event) {
console.log( event.query )
// this.mylookupservice.getResults(event.query).then(data => {
// this.results = data;
// });
}
constructor( private _autocompleteService:AutocompleteService ) { }
ngOnInit() {
}
}
autocomplete.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class AutocompleteService {
datos:any[] = [];
urlBusqueda:string = "http://localhost:3000/consultas/";
constructor( private http:Http ) { }
getDatos(termino:string){
console.log( termino );
// let query = `${ termino }`
// let url = this.urlBusqueda + query;
// return {};
// console.log( url );
}
}
此外,我在app.module.ts中引用了组件和服务。我可能做错了什么?
最佳答案
上面的建议对我不起作用,但是this起作用了-我需要将FormsModule添加到我的共享模块中,例如:
//...
import { FormsModule } from '@angular/forms';
import { AutoCompleteModule } from 'primeng/primeng';
//...
@NgModule({
imports: [
//...
FormsModule,
AutoCompleteModule,
//...
]
//...
关于javascript - Angular4。我不能使用自动完成功能-primeNG,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44231049/