无法绑定到“控件",因为它不是(myComponent)的已知属性 [英] Can't bind to 'control' since it isn't a known property of (myComponent)

查看:69
本文介绍了无法绑定到“控件",因为它不是(myComponent)的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的app.module.ts

this is my app.module.ts

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组件:

I have this angular2 components:

从'../error-messages.component'导入{ErrorMessagesComponent}; 从"../validation.component"导入{ValidationComponent}; 从"../gas-type"中导入{GasType};

import {ErrorMessagesComponent} from '../error-messages.component'; import {ValidationComponent} from '../validation.component'; import {GasType} from "../gas-type";

export class CountryDetailsComponent extends LoadingPage implements OnInit {
  countryName: string;
  productionForm: FormGroup;

..
}

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:

              <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>

但我收到此错误:

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

我该如何解决?

推荐答案

该组件需要在@NgModule()

declarations: [ AppComponent, ErrorMessageComponent ],

这篇关于无法绑定到“控件",因为它不是(myComponent)的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆