简体   繁体   English

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

[英]Error: Template parse errors: Can't bind to 'myProperty' since it isn't a known property of 'myComponent'

After upgrading from Angular 2.1.0 to 2.4.3 and webpack from 2.1.0-beta.25 to 2.2.0-rc.4 I recive this error if i run my webapp (the build works fine without errors):从 Angular 2.1.0 升级到 2.4.3 并将 webpack 从 2.1.0-beta.25 升级到 2.2.0-rc.4 后,如果我运行我的 webapp(构建工作正常,没有错误),我会收到此错误:

Error: Template parse errors: Can't bind to 'center' since it isn't a known property of 'placeFilter'. 

At the moment I have one single central model like this (yes I know :-) I will change it afterwards):目前我有一个这样的中央模型(是的,我知道:-)我会在之后更改它):

    import { NgModule }      from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';

    import { AppRoutingModule } from './app.routes';

    ...
    import {MapComponent} from './map/map/map.component';
   ...
    import {PlaceFilterComponent} from './map/shared/components/placeFilter.component';
    ...

    @NgModule({
        imports: [BrowserModule, AppRoutingModule, FormsModule, HttpModule],
        declarations: [...
            MapComponent,
           ...
            PlaceFilterComponent,
            ...
        ],
        bootstrap: [AppComponent]
    })

    export class AppModule { }

My MapComponent contains a sub component called PlaceFilterComponent:我的 MapComponent 包含一个名为 PlaceFilterComponent 的子组件:

import { Component, OnInit, OnDestroy, Input, Output, NgZone  } from '@angular/core';
import { ActivatedRoute, Params, Router} from '@angular/router';
import {Subscription} from "rxjs";
import {TimerObservable} from "rxjs/observable/TimerObservable";

import services

import models

@Component({
    selector: 'emersy-content',
    templateUrl: './map.component.html',
    providers: [myServices]
})

export class MapComponent implements OnInit, OnDestroy {
...

    constructor(private placeService: PlaceService, private externalService: ExternalServiceService, private zone: NgZone, private route: ActivatedRoute, private router: Router) {
        ...

        });
    }

   ...
}

Here my MapComponentTemplate:这是我的 MapComponentTemplate:

<div class="filterbox-map" *ngIf="!onlyMap">
    <place-filter (onSearchLocationChange)="searchLocationChange($event)" (onShowSideBarButtonClick)="showSideBarButtonClick()" [center]="center" [searchTerm]="searchTerm"></place-filter>
</div>

And my PlaceFilter Component is made like this:我的 PlaceFilter 组件是这样制作的:

import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';

import {Center} from '../models/center'

declare var google: any;

@Component({
    selector: 'place-filter',
    templateUrl: './placeFilter.component.html'
})

export class PlaceFilterComponent {
...
    private _center: Center;    
    get center() {
        return this._center;
    }
    @Input() set center(center: Center) {
        this._center = center;
    }



    constructor() {

    } 
...
}

My folder structure is like this:我的文件夹结构是这样的:

app
L app.module.ts
L map
 L map
 | L map.component.ts
 | L map.component.html
 L shared
  L components
    L placefilter.component.ts
    L placefilter.component.html
export class PlaceFilterComponent {
...
    private _center: Center;    
    get center() {
        return this._center;
    }
    // try like this 
    @Input() center:Center;



    constructor() {

    } 
...
}

Sometimes we forgot to check some basic things, and this happened with me in my Angular application.有时我们忘记检查一些基本的东西,这发生在我的Angular应用程序中。 I created a new component with the command ng gc audio-element and I used them in another component.我使用命令ng gc audio-element创建了一个新组件,并在另一个组件中使用了它们。

<!--AUDIO-->
<div *ngIf="theWorksheetElement?.type === 7" class="fill">
    <audio-element [worksheetElement]="theWorksheetElement" [style.pointer-events]="isResizing ? 'none' : 'auto'"></audio-element>
</div>

And I was always getting the error as follows.我总是收到如下错误。

ERROR Error: Uncaught (in promise): Error: Template parse errors: Can't bind to 'worksheetElement' since it isn't a known property of 'audio-element'.错误错误:未捕获(承诺):错误:模板解析错误:无法绑定到“worksheetElement”,因为它不是“音频元素”的已知属性。 1. If 'audio-element' is an Angular component and it has 'worksheetElement' input, then verify that it is part of this module. 1. 如果 'audio-element' 是一个 Angular 组件并且它有 'worksheetElement' 输入,那么验证它是这个模块的一部分。 2. If 'audio-element' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 2. 如果'audio-element' 是一个Web 组件,则将'CUSTOM_ELEMENTS_SCHEMA' 添加到该组件的'@NgModule.schemas' 以抑制此消息。

I was sure that I added this component to my related module.我确信我将此组件添加到我的相关模块中。 Now comes the funny part my selector was different in the component typescript file.现在有趣的部分是我的选择器在组件打字稿文件中有所不同。

@Component({
  selector: 'app-audio-element',
  templateUrl: './audio-element.component.html',
  styleUrls: ['./audio-element.component.scss']
})

I changed the app-audio-element to audio-element and then it started working as expected.app-audio-element更改audio-element ,然后它开始按预期工作。 Just sharing for the people who might be making the same problem.只是分享给可能遇到同样问题的人。

暂无
暂无

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

相关问题 错误:模板解析错误:无法绑定到“ ngForOf”,因为它不是“模板”的已知属性 - Error: Template parse errors: Can't bind to 'ngForOf' since it isn't a known property of 'template' 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) 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' 错误:模板解析错误:无法绑定到“评级”,因为它不是“评级”的已知属性 - Error: Template parse errors: Can't bind to 'rating' since it isn't a known property of 'rating' 未捕获的错误:模板解析错误:无法绑定到“ FormGroup”,因为它不是“ form”的已知属性 - Uncaught Error: Template parse errors: Can't bind to 'FormGroup' since it isn't a known property of 'form' 错误:模板解析错误:无法绑定到“选项”,因为它不是“图表”的已知属性 - Error: Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart' 未捕获错误:模板解析错误:无法绑定到&#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' 未捕获(承诺):错误:模板解析错误:由于它不是“输入”的已知属性,因此无法绑定到“上载器” - 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 Ngx无限滚动 - 模板解析错误:无法绑定到&#39;infiniteScrollDistance&#39;,因为它不是已知属性 - Ngx infinite scrolling - Template parse errors: Can't bind to 'infiniteScrollDistance' since it isn't a known property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM