如何找到哪些组件存在冲突?

时间:2017-06-16 10:21:08

标签: angular

我使用的是Angular 2的ES5风味。 我遇到了这个错误:

Unhandled Promise rejection: Template parse errors:
More than one component matched on this element.
Make sure that only one component's selector can match a given element.
Conflicting components: class2,class6 ("
    </tbody>
</table>
[ERROR ->]<paging [data]="data" (changed)="loadCountries($event)" unit="country"></paging>
<md-spinner class="lis"): class18@30:0 ; Zone: <root> ; Task: Promise.then ; Value: 

它说class2class6。我无法找到班级的原始名称。

这是我的模块定义:

var module = ng.core.NgModule({
    imports: [
        ng.platformBrowser.BrowserModule, 
        ng.router.RouterModule.forRoot([].concat([...])), 
        ng.material.MaterialModule, 
        ng.http.HttpModule, 
        ng.common.CommonModule, 
        ng.forms.FormsModule],
    declarations: [
        app.CoalAddWorldCoalSupply, 
        app.FilterValuesDialog, 
        app.CoalFlows, 
        app.ImportWorldCoalSupplies, 
        app.CoalProducts, 
        app.CoalReports, 
        app.CoalUpsertFlow, 
        app.CoalUpsertProduct, 
        app.CoalWorldCoalSupplies, 
        app.CountryList, 
        app.CountryUpsert, 
        app.Dashboard, 
        app.ElectricityHeatGenerations, 
        ...
        ],
    entryComponents: [app.FilterValuesDialog, confirmDialog],
    bootstrap: [app.Layout],
    providers: [globalService]
})
.Class({
    constructor: function () { }
});

document.addEventListener('DOMContentLoaded', function () {
    ng.platformBrowserDynamic
      .platformBrowserDynamic()
      .bootstrapModule(module);
});

使用...指定的部件意味着更多相同的事情。

如何理解zone.js所指的哪个班级?

1 个答案:

答案 0 :(得分:13)

我们说我们有以下应用:

<强> app.component.js

app.AppComponent = Component({
  selector: 'my-app',
  template:
    '<h1>(es5) angular2 4.1.3</h1><comp1></comp1>'
})
.Class({
  constructor: function AppComponent() {}
});

<强> component1.js

app.Component1 = Component({
  selector: 'comp1',
  template:
    'component1'
})
.Class({
  constructor: function Component1() {}
});

<强> component2.js

app.Component2 = Component({
  selector: 'comp1',
  template:
    'component2'
})
.Class({
  constructor: function Component2() {}
});

Expected Result

所以我的行动:

https://plnkr.co/edit/AKBVbX9ruZM8DchFcfbh?p=preview