2017-06-16 20 views
4

我使用的角度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"): [email protected]: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所指的類別?

回答

5

比方說,我們有以下應用:

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() {} 
}); 

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

所以我的操作:

enter image description here

+1

sooooooooooooo涼爽。 +1 –

+0

非常感謝您製作該gif並展示如何調試和查找相沖突的組件。我不會想到我自己。對於我的問題,我正在導入一個導出MatButtonModule的UI庫,但我的主項目也是如此。通過像這樣調試,我能夠發現兩個UI庫都在導出MatButtonModule,這就產生了一個衝突,因爲現在我的項目有兩個競爭渲染這個材質的es5.js文件模塊 –

+0

我承認我必須觀察調試幾次想要看看你在做什麼,我唯一的願望是它沒有跑得這麼快,但是我能夠跟隨並最終弄清楚。 –