Angular 角形7罐';t绑定到<;房地产>;因为它不是';t为<;组件>;(来自导入的模块)
我有一个模块正在导入另一个模块以使用其中声明的组件。在下面的示例中,Angular 角形7罐';t绑定到<;房地产>;因为它不是';t为<;组件>;(来自导入的模块),angular,typescript,Angular,Typescript,我有一个模块正在导入另一个模块以使用其中声明的组件。在下面的示例中,moduleComponentC正在尝试使用moduleComponentA。似乎ModuleA需要导入ModuleB才能使用它,因此,ModuleB需要导出ModuleB组件A。看起来很简单,但下面的内容对我来说并不适用 我得到无法绑定到'name',因为它不是'module-b-component-a'的已知属性。 src/a/moduleA.module.ts src/b/moduleB.module.ts src/b/a
moduleComponentC
正在尝试使用moduleComponentA
。似乎ModuleA
需要导入ModuleB
才能使用它,因此,ModuleB
需要导出ModuleB组件A
。看起来很简单,但下面的内容对我来说并不适用
我得到无法绑定到'name',因为它不是'module-b-component-a'的已知属性。
src/a/moduleA.module.ts
src/b/moduleB.module.ts
src/b/a.component.ts
src/a/c.component.html
您错过的是在
@Input()
中指定name
:
@组件({
选择器:“模块b-组件a”
})
导出类模块组件A{
@Input('name')name:string;//Try:@Input('name'))name:string
inModuleBComponentA
Ha!这就解决了。我在这个问题上绞尽脑汁已经太久了。请随意把它作为实际答案,我会接受的!哈哈。谢谢:)我不熟悉AngularJS。如果你想寻找更好的方法,你当然可以使用属性绑定:
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CommonModule } from "@angular/common"
import { ModuleAComponentC } from './c.component'
import { ModuleAComponentD } from './d.component'
import { ModuleB } from './../b/b.module'
@NgModule({
imports: [
BrowserModule,
CommonModule,
ModuleB
],
declarations: [
ModuleAComponentC,
ModuleAComponentD
]
})
export class ModuleA {}
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CommonModule } from "@angular/common"
import { ModuleBComponentA } from './a.component'
import { ModuleBServiceA } from './a.service'
@NgModule({
imports: [
BrowserModule,
CommonModule
],
declarations: [
ModuleBComponentA
],
providers: [
ModuleBServiceA
],
exports: [
ModuleBComponentA
]
})
export class ModuleB {}
@Component({
selector: 'module-b-component-a'
})
export class ModuleBComponentA {
@Input('@') name: string
}
<module-b-component-a name="{{ test }}"></module-b-component-a>
@Component({
selector: 'module-b-component-a'
})
export class ModuleBComponentA {
@Input('name') name: string; // <-- 'name' in place of '@'
}