首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法绑定到“control”,因为它不是(myComponent)的已知属性

无法绑定到“control”,因为它不是(myComponent)的已知属性
EN

Stack Overflow用户
提问于 2016-10-19 17:46:48
回答 1查看 987关注 0票数 3

这是我的app.module.ts

代码语言:javascript
复制
import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule }    from '@angular/http';
import { AppComponent }  from './app.component';
// import { CountryDetailsComponent} from './country-detail.component';
// import { LandingPageComponent} from './landing-page.component';
import { routing } from './app.routing'
import { TypeaheadModule } from 'ng2-bootstrap/components/typeahead';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TabsModule } from 'ng2-bootstrap/ng2-bootstrap';
import { CollapseModule } from 'ng2-bootstrap/ng2-bootstrap';
import { AlertModule } from 'ng2-bootstrap/ng2-bootstrap';


@NgModule({
    imports:      [ BrowserModule, HttpModule, routing, FormsModule, ReactiveFormsModule, TypeaheadModule, TabsModule, CollapseModule, AlertModule],
    declarations: [ AppComponent ],
    providers: [],
    bootstrap:    [ AppComponent ]
})
export class AppModule { }

我有这个angular2组件:

从‘../error-Messages.Component’导入{ErrorMessagesComponent};从‘../validation.component’导入{ValidationComponent};从‘../gas-type’导入{GasType};

代码语言:javascript
复制
export class CountryDetailsComponent extends LoadingPage implements OnInit {
  countryName: string;
  productionForm: FormGroup;

..
}

代码语言:javascript
复制
import { Component, Input } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { ValidationComponent } from './validation.component';

@Component({
  selector: 'error-messages',
  template: `<div style="color:#E82C0C; margin: 6px 0;" *ngIf="errorMessage !== null">{{errorMessage}}</div>`
})
export class ErrorMessagesComponent {
  @Input() control: FormControl;
  constructor() { }

和模板country-details.component.html

代码语言:javascript
复制
              <div class="col-lg-10 ">
                <input class="price-format form-control" type="text"
                       [formControl]="productionForm.controls.priceFormat"
                       [(ngModel)]="productionConfig.priceFormat"
                       id="inputPriceFormat"
                       name="priceFormat">
                <error-messages [control]="productionForm.controls.priceFormat"></error-messages>
              </div>

但是我得到了这个错误:

代码语言:javascript
复制
Can't bind to 'control' since it isn't a known property of 'error-messages'.
1. If 'error-messages' is an Angular component and it has 'control' input, then verify that it is part of this module.
2. If 'error-messages' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message.
 ("nputPriceFormat"
                           name="priceFormat">
                    <error-messages [ERROR ->][control]="productionForm.controls.priceFormat"></error-messages>
                  </div>
          "): b@43:36

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2016-10-19 17:48:25

该组件需要向@NgModule()注册

代码语言:javascript
复制
declarations: [ AppComponent, ErrorMessageComponent ],
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40127790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档