我有一个简单的 Angular2 应用程序,它包含App
, P1
, P2
,Child
总共 4 个组件,其中App
使用P1
and P2
,两者都使用P1
and 。P2
Child
这是代码:
@Component({
selector: 'child',
template: '<div> child <div>',
})
export class ChildCmp {}
@Component({
selector: 'p1',
template: '<div> P1: <child></child></div>',
directives:[ChildCmp],
})
export class P1Cmp {}
@Component({
selector: 'p2',
template: '<div> P2: <child></child><child></child></div>',
directives:[ChildCmp],
})
export class P2Cmp {}
@Component({
selector: 'my-test',
template: '<p1></p1><p2></p2>',
directives:[P1Cmp, P2Cmp],
})
export class TestApp {}
bootstrap(TestApp);
触发应用程序的index.html<my-test></my-test>
包含所有必需的 Angular2 库。
您可以在Plunker中查看演示,控制台日志显示
EXCEPTION: TypeError: viewFactory_ChildCmp0 is not a function
这个应用程序在 Angular2 初始化中中断,一旦我将Child
两者都放入P1
和P2
中,它就会中断。
知道它为什么会坏吗?