1

Kendo UI を使用して実行できた、Kendo を使用してデモ アプリケーションを作成しようとしています。今度は、Angular 2 Kendo UI を使用して同じことを試す必要があります。ただし、次のエラーで立ち往生しました。

私のコンポーネントコードは次のようになります。Kendo UI のサンプル コードと同じです。

import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
        <kendo-grid [data]="gridData">
            <kendo-grid-column field="ProductID" title="Product ID" width="120">
            </kendo-grid-column>
            <kendo-grid-column field="ProductName" title="Product Name">
            </kendo-grid-column>
            <kendo-grid-column field="UnitPrice" title="Unit Price" width="230">
            </kendo-grid-column>
            <kendo-grid-column field="Discontinued" width="120">
                <template kendoCellTemplate let-dataItem>
                    <input type="checkbox" [checked]="dataItem.Discontinued" disabled/>
                </template>
            </kendo-grid-column>
        </kendo-grid>
    `
})
export class GridComponent {

    private gridData: any[] = [{
        "ProductID": 1,
        "ProductName": "Chai",
        "UnitPrice": 18.0000,
        "Discontinued": true
    }, {
        "ProductID": 2,
        "ProductName": "Chang",
        "UnitPrice": 19.0000,
        "Discontinued": false
    }, {
        "ProductID": 3,
        "ProductName": "Aniseed Syrup",
        "UnitPrice": 10.0000,
        "Discontinued": false
    }, {
        "ProductID": 4,
        "ProductName": "Chef Anton's Cajun Seasoning",
        "UnitPrice": 22.0000,
        "Discontinued": false
    }, {
        "ProductID": 5,
        "ProductName": "Chef Anton's Gumbo Mix",
        "UnitPrice": 21.3500,
        "Discontinued": false
    }, {
        "ProductID": 6,
        "ProductName": "Grandma's Boysenberry Spread",
        "UnitPrice": 25.0000,
        "Discontinued": false
    }];
}

次の詳細を持つ共通のモジュールクラスがあります

import { NgModule } from '@angular/core';
import { CommonModule }  from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { BookDetailComponent } from './distribution-detail/distribution-detail.component';
import { GridComponent } from './detail-grid/detail-grid.component';
import { GridModule } from '@progress/kendo-angular-grid';


@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        SharedModule,
        HttpModule,
        GridModule
    ],
    declarations: [
        BookDetailComponent,
        GridComponent
    ],
    providers: [
        DistributionService
    ]
})

export class DistributionModule { }

また、Grid Module セレクターは BookDetailComponent HTML コードで使用され、

<my-app>Loading</my-app>

ただし、エラーが発生します

core.umd.js:2837 EXCEPTION: Uncaught (in promise): エラー: テンプレート解析エラー: 「grid-demo」は既知の要素ではありません: 1.「my-app」が Angular コンポーネントの場合は、それがこのモジュールの一部です。

4

1 に答える 1

3

IfDistributionModuleは共通モジュールです。そして、このモジュールを にインポートしてから、とを の export 配列にAppModule追加する必要があります。GridComponentBookDetailComponentDistributionModule

@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        SharedModule,
        HttpModule,
        GridModule
    ],
    declarations: [
        BookDetailComponent,
        GridComponent
    ],
    exports : [
       BookDetailComponent,
       GridComponent
    ],
    providers: [
        DistributionService
    ]
})

このようにして、内部で定義されたコンポーネントを実際に使用できますDistributionModule

于 2016-11-29T11:12:59.943 に答える