NgbTypeahead + MVC后端

时间:2017-10-26 10:47:15

标签: c# asp.net-mvc angular bootstrap-typeahead ng-bootstrap

我尝试使用c#结果实现NgbTypeahead但不起作用

autocomplete.ts

import { IPeople } from '../components/people';
@Injectable()
@Component({
    selector: 'autocomplete-eid',
    templateUrl: './autocomplete.component.html',
})
export class NgbdTypeaheadHttp {
    model: any;
    searching = false;
    searchFailed = false;
    hideSearchingWhenUnsubscribed = new Observable(() => () => this.searching = false);

    constructor(private _service: PeopleService) { }

    search = (text$: Observable<string>) => 
        text$
            .debounceTime(300)
            .distinctUntilChanged()
            .do(() => this.searching = true)
            .switchMap(term =>
                this._service.search(term)
                    .do(() => this.searchFailed = false)
                    .catch(() => {
                        this.searchFailed = true;
                        return Observable.of([]);
                    }))
            .do(() => this.searching = false)
            .merge(this.hideSearchingWhenUnsubscribed);

}

PeopleService

@Injectable()

export class PeopleService{
    public lstPeople : Array<IPeoplePicker>;
    constructor(private _jsonp: Jsonp) { }

    search(term: string) {
        if (term === '') {
            return Observable.of([]);
        }

        //let wikiUrl = 'https://en.wikipedia.org/w/api.php';
        let urlPeopleServiceApi = Global.BASE_HOME_ENDPOINT_2;
        let params = new URLSearchParams();
        params.set('value', term);

        return this._jsonp
            .get(urlPeopleServiceApi, { search: params })
            .map(response => <IPeoplePicker[]>response.json()[1]);
    }
}

和MVC控制器返回 IEnumerable

public IEnumerable<People> Get(string value)
{


    var Settings = SettingsRepository.Settings;

    ActiveDirectorySearcher searcher = new ActiveDirectorySearcher(Settings.LDAPPath, Settings.LDAPUserName, Settings.LDAPPassword);
    List<People> data = null;

    data = searcher.FindAll(); todos

    return data;
} 

如何使用Ipeople角度等级获得结果?你知道为typeahead ng-bootstrap类实现可观察结果的指南吗?

谢谢!

0 个答案:

没有答案