Javascript Can';因为它不是';t选择器组件的已知属性
我想将一个变量从一个组件传递到另一个组件,我正在使用@input 这是我的父组件:Javascript Can';因为它不是';t选择器组件的已知属性,javascript,angular,typescript,angular8,Javascript,Angular,Typescript,Angular8,我想将一个变量从一个组件传递到另一个组件,我正在使用@input 这是我的父组件: @Component({ selector: 'aze', templateUrl: './aze.component.html', styleUrls: [('./aze.component.scss')], providers: [PaginationConfig], }) export class azeComponent implements OnInit { p
@Component({
selector: 'aze',
templateUrl: './aze.component.html',
styleUrls: [('./aze.component.scss')],
providers: [PaginationConfig],
})
export class azeComponent implements OnInit {
public hellovariable: number = 100;
}
@Component({
selector: 'app-my-dialog',
templateUrl: './my-dialog.component.html',
styleUrls: ['./my-dialog.component.css']
})
export class MyDialogComponent implements OnInit {
@Input() hellovariable: number;
constructor() { }
ngOnInit() {
console.log(hellovariable);
}
这是父组件的模板:
<app-my-dialog [hellovariable]="hellovariable"></app-my-dialog>
这是子模板:
<h3>Hello I am {{hellovariable}}<h3>
确定此错误的原因是您需要在azeComponent的模块中导入MyDialogComponent。没有什么可以尝试的 首先,确保已将输入导入到组件中
import { Component, Input } from '@angular/core';
然后在命名类时遵循pascal约定
export class azeComponent implements OnInit
应改为
export class AzeComponent implements OnInit
然后将组件注册到模块声明中
也可以将BrowserModule导入到您的模块中
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
MyDialogComponent,
AzeComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
大多数情况下,您会出现此错误,因为您忘记将组件声明到
app.module.ts
中,或者是错误的
app.module.ts
您的特定.component.ts
组件是否已添加到模块中?您的意思是在app.module.ts中,我是否已在声明中添加父组件?我刚刚将父组件添加到声明中,我将遇到另一个错误,无法绑定到“dataSource”,因为它不是“table”的已知属性您正在使用的Angular 8和前面的库角材料节点12.9.1请更新完整代码。如果我看不到您的代码,我将无法帮助您。我已将app.module.ts添加到问题中
import { YourSpecificComponent } from './components/measureUnit/measure-unit-monthly/measure-unit-monthly.component';
@NgModule({
declarations: [
AppComponent,
MessageComponent,
DashboardComponent,
.....,
YourSpecificComponent, // declared here
}
@Component({
selector: 'app-your-specific', // your selector
templateUrl: './your-specific.component.html',
styleUrls: [
'../some.css'
]
})
export class YourSpecificComponent implements AfterContentInit {
.....