angular – 如何在Reactive Form上使用ng-bootstrap Typeahead组
发布时间:2020-12-17 18:01:50 所属栏目:安全 来源:网络整理
导读:我正在尝试在带有Angular 2的Reactive Form上使用ng-bootstrap Typeahead组件,在查看 Typeahead’s documentation上的示例代码后,我无法使其工作. 目前,我有类似的东西: input type="text" aria-describedby="cityValid" class="form-control" id="inputCit
我正在尝试在带有Angular 2的Reactive Form上使用ng-bootstrap Typeahead组件,在查看
Typeahead’s documentation上的示例代码后,我无法使其工作.
目前,我有类似的东西: <input type="text" aria-describedby="cityValid" class="form-control" id="inputCity" [formControl]="userForm.controls.city" [ngbTypeahead]="search"> 使用与示例代码几乎相同的搜索功能,但它会因以下堆栈跟踪而失败 error_handler.js:53 TypeError: Cannot read property 'subscribe' of undefined at NgbTypeahead._subscribeToUserInput (typeahead.js:158) at NgbTypeahead.ngOnInit (typeahead.js:52) at DebugAppView._View_UserFormComponent0.detectChangesInternal (UserFormComponent.ngfactory.js:1093) at DebugAppView.AppView.detectChanges (view.js:271) at DebugAppView.detectChanges (view.js:376) at DebugAppView.AppView.detectViewChildrenChanges (view.js:297) at DebugAppView._View_ExecutionFormComponent3.detectChangesInternal (ExecutionFormComponent.ngfactory.js:551) at DebugAppView.AppView.detectChanges (view.js:271) at DebugAppView.detectChanges (view.js:376) at DebugAppView.AppView.detectContentChildrenChanges (view.js:289) 我究竟做错了什么?如果有一个关于如何在Reactive Forms上使用ng-bootstrap组件的一般指南会很棒,因为该示例基于基于模板的示例. 谢谢! 解决方法
没关系,问题是我采用了示例中出现的搜索功能并将其转换为普通函数但没有返回任何值.
我有 searchCity (text$: Observable<string>) { text$ .debounceTime(200) .distinctUntilChanged() .map(term => term.length < 2 ? [] : cities.filter(v => new RegExp(term,'gi').test(v)).splice(0,10)); } 在text $fixed之前添加一个return语句. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |