Angular 2 DropDown组件问题

时间:2016-11-27 20:07:36

标签: angular angular2-forms angular2-directives

根据SO question实现下拉组件绑定属性时出错是错误的,这是通过以下设置将下拉值(selectItem)绑定到product.categoryId的正确方法吗?:

html的

<div *ngIf="product">
    <h2>{{product.name}}</h2>
    <div>
        <label>Id: </label>{{product.productId}}
    </div>
    <div>
        <label>Name: </label>
        <input [(ngModel)]="product.name" placeholder="name" />
    </div>
    <div>
        <label>Price: </label>
        <input [(ngModel)]="product.price" placeholder="price" />
    </div>
    <div>
        <label>Image name: </label>
        <input [(ngModel)]="product.imageName" placeholder="imageName" />
    </div>
    <div>
        <label>Thumb image name: </label>
        <input [(ngModel)]="product.thumbImageName" placeholder="thumbImageName" />
    </div>
    <dropdown [values]="dropdownValues" (select)="action($event.value)"></dropdown>
    <div>
        <label>Category Id: </label>
        <!-->input [(ngModel)]="product.categoryId" placeholder="categoryId" /-->
    <!--Trying to bind this property with selectItem from DropdownComponent/-->
        {{product.categoryId}}
    </div>

    <button (click)="goBack()">Back</button>
    <button (click)="save()">Save</button>
</div>

错误浏览器

zone.js:388Unhandled Promise rejection: Template parse errors:
Can't bind to 'values' since it isn't a known property of 'dropdown'. ("             {{product.price}}
                {{product.categoryName}}
                <dropdown [ERROR ->][values]="dropdownValues" (select)="action($event.value)"></dropdown>
                {{product.thum"): ProductsApiComponent@8:26
'dropdown' is not a known element:
1. If 'dropdown' is an Angular component, then verify that it is part of this module.
2. If 'dropdown' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
                {{product.price}}
                {{product.categoryName}}
                [ERROR ->]<dropdown [values]="dropdownValues" (select)="action($event.value)"></dropdown>
                {{pr"): ProductsApiComponent@8:16 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors:
Can't bind to 'values' since it isn't a known property of 'dropdown'. ("             {{product.price}}
                {{product.categoryName}}
                <dropdown [ERROR ->][values]="dropdownValues" (select)="action($event.value)"></dropdown>
                {{product.thum"): ProductsApiComponent@8:26
'dropdown' is not a known element:
1. If 'dropdown' is an Angular component, then verify that it is part of this module.
2. If 'dropdown' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
                {{product.price}}
                {{product.categoryName}}
                [ERROR ->]<dropdown [values]="dropdownValues" (select)="action($event.value)"></dropdown>
                {{pr"): ProductsApiComponent@8:16
    at TemplateParser.parse (http://localhost:18678/dist/app.bundle.js:20029:19)
    at RuntimeCompiler._compileTemplate (http://localhost:18678/dist/app.bundle.js:43294:51)
    at http://localhost:18678/dist/app.bundle.js:43214:62
    at Set.forEach (native)
    at RuntimeCompiler._compileComponents (http://localhost:18678/dist/app.bundle.js:43214:19)
    at createResult (http://localhost:18678/dist/app.bundle.js:43110:19)
    at ZoneDelegate.invoke (http://localhost:18678/dist/app.bundle.js:92363:26)
    at Zone.run (http://localhost:18678/dist/app.bundle.js:92245:43)
    at http://localhost:18678/dist/app.bundle.js:92633:57
    at ZoneDelegate.invokeTask (http://localhost:18678/dist/app.bundle.js:92396:35)
    at Zone.runTask (http://localhost:18678/dist/app.bundle.js:92285:47)
    at drainMicroTaskQueue (http://localhost:18678/dist/app.bundle.js:92532:35)

1 个答案:

答案 0 :(得分:0)

您的问题可能是因为您没有将此组件导入使用它的模块中。你得到的错误信息正是我忽略导入它时得到的错误信息。