简体   繁体   English

模板解析错误:无法绑定到“ngbTypeahead”,因为它不是“input”的已知属性

[英]Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input'

I get the error "Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input' " when I run my angular project.当我运行我的 angular 项目时,我收到错误“模板解析错误:无法绑定到 'ngbTypeahead' 因为它不是 'input' 的已知属性”。 Looked everywhere but couldn't find a solution.到处寻找,但找不到解决方案。

Here is my html.这是我的 html。

<div class="kt-section__content">
    <label for="typeahead-basic">Search for a state:</label>
    <input id="typeahead-basic" type="text" class="form-control" [(ngModel)]="model" [ngbTypeahead]="search" />
</div>

Here is the component.ts这是component.ts

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, map } from 'rxjs/operators';

const states = ['Alabama', 'Alaska', 'American Samoa', 'Arizona', 'Arkansas', 'California', 'Colorado',
  'Connecticut', 'Delaware', 'District Of Columbia', 'Federated States Of Micronesia', 'Florida', 'Georgia',
  'Guam', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine',
  'Marshall Islands', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana',
  'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
  'Northern Mariana Islands', 'Ohio', 'Oklahoma', 'Oregon', 'Palau', 'Pennsylvania', 'Puerto Rico', 'Rhode Island',
  'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virgin Islands', 'Virginia',
  'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];

@Component({
  selector: 'kt-grn',
  templateUrl: './grn.component.html',
  styleUrls: ['./grn.component.scss']
})
export class GrnComponent implements OnInit {
  public model: any;

  search = (text$: Observable<string>) =>
    text$.pipe(
      debounceTime(200),
      distinctUntilChanged(),
      map(term => term.length < 2 ? []
        : states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
    )

  constructor() { }

  ngOnInit() {
  }

}

And here's the code from app.module.ts这是来自 app.module.ts 的代码

import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
    declarations: [AppComponent],
    imports: [
        BrowserAnimationsModule,
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        NgbModule,
    ],
    exports: [],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}

Could somebody help me?有人可以帮助我吗?

You need to import the NgbTypeaheadModule as well.您还需要导入 NgbTypeaheadModule。

import { NgbModule, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
    declarations: [AppComponent],
    imports: [
        BrowserAnimationsModule,
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        NgbModule,
        NgbTypeaheadModule
    ],
    exports: [],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}

Edit: this is more to do with how the library requires you to use their library rather than a pure Angular thing.编辑:这更多地与库如何要求您使用他们的库而不是纯粹的 Angular 东西有关。 Some libraries will give you everything in one module.一些库将在一个模块中为您提供所有内容。 UI component modules like Material and NgbBootstrap allow you to import component modules individually, so you can keep the size of the imported javascript down to a minimum.像 Material 和 NgbBootstrap 这样的 UI 组件模块允许您单独导入组件模块,因此您可以将导入的 javascript 的大小保持在最小。

失败:模板解析错误:无法绑定到“ngModel”,因为它不是“输入”的已知属性。 ("<div class="input-group"> *</div><div id="text_translate"><p> 更新到 angular 12 后,出现以下错误。</p><p> 项目正在构建和运行,但每当我尝试<strong>ng test</strong>进行单元测试时,我都会遇到以下错误</p><p><em>失败:模板解析错误:无法绑定到“ngModel”,因为它不是“输入”的已知属性。</em> <em>("</em></p><p> 我尝试<strong>从 '@angular/forms' 导入 import { FormsModule, ReactiveFormsModule };</strong> 但仍然是同样的错误。 请帮我解决这个问题。</p></div> - Failed: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'. (" <div class="input-group">*

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模板解析错误:无法绑定到'ngbTypeahead',因为它不是'input的已知属性 - Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input 未捕获错误:模板解析错误:无法绑定到&#39;ngModel&#39;,因为它不是&#39;input&#39;的已知属性 - Uncaught Error: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input' Angular 2:模板解析错误:无法绑定到&#39;ngModel&#39;,因为它不是&#39;input&#39;的已知属性 - Angular 2: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input' 未捕获(承诺):错误:模板解析错误:由于它不是“输入”的已知属性,因此无法绑定到“上载器” - Uncaught (in promise): Error: Template parse errors: Can't bind to 'uploader' since it isn't a known property of 'input' 许多失败:模板解析错误:无法绑定到“routerLink”,因为它不是“a”的已知属性。 Karma 中的错误 - Lots of Failed: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. errors in Karma 失败:模板解析错误:无法绑定到“ngModel”,因为它不是“输入”的已知属性。 ("<div class="input-group"> *</div><div id="text_translate"><p> 更新到 angular 12 后,出现以下错误。</p><p> 项目正在构建和运行,但每当我尝试<strong>ng test</strong>进行单元测试时,我都会遇到以下错误</p><p><em>失败:模板解析错误:无法绑定到“ngModel”,因为它不是“输入”的已知属性。</em> <em>("</em></p><p> 我尝试<strong>从 '@angular/forms' 导入 import { FormsModule, ReactiveFormsModule };</strong> 但仍然是同样的错误。 请帮我解决这个问题。</p></div> - Failed: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'. (" <div class="input-group">* 错误:模板解析错误:无法绑定到“ ngForOf”,因为它不是“模板”的已知属性 - Error: Template parse errors: Can't bind to 'ngForOf' since it isn't a known property of 'template' 例外:模板解析错误:由于它不是已知的本机属性,因此无法绑定到“ ngForFrom” - EXCEPTION: Template parse errors: Can't bind to 'ngForFrom' since it isn't a known native property Ngx无限滚动 - 模板解析错误:无法绑定到&#39;infiniteScrollDistance&#39;,因为它不是已知属性 - Ngx infinite scrolling - Template parse errors: Can't bind to 'infiniteScrollDistance' since it isn't a known property Angular中的错误:模板解析错误:无法绑定到&#39;datetime&#39;,因为它不是&#39;time&#39;的已知属性 - Error in Angular: Template parse errors: Can't bind to 'datetime' since it isn't a known property of 'time'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM