试图实现Kendo UI angular 2 Grid Selector Error

时间:2016-11-29 11:07:56

标签: angular kendo-grid kendo-ui-angular2

我正在尝试使用Kendo创建一个演示应用程序,我可以使用Kendo UI。现在我需要使用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:未捕获(在承诺中):错误:模板解析错误: &#39;网格演示&#39;不是一个已知的元素: 1.如果&#39; my-app&#39;是一个Angular组件,然后验证它是否是该模块的一部分。

1 个答案:

答案 0 :(得分:2)

如果DistributionModule是您的常用模块。然后您将此模块导入到AppModule,然后您应将GridComponentBookDetailComponent添加到DistributionModule的导出数组中:

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

这样您就可以实际使用DistributionModule

中定义的组件