Member 13045401 Ответов: 0

Не показывать компонент, когда я использовал [(ngmodel)] и [рейтинг] в angular 2


i used angular 2 in asp mvc 5

 when i used this code for tow way-binding my component is not show any thing and it       not show me any error 

<pre lang="Javascript"><pre><input type='text' class="form-control" [(ngModel)]="listFilter" 
[ngModelOptions]="{standalone: true}" />


и этот код та же проблема :

<ai-star [rating]='product.starRating'
           (ratingClicked)='onRatingClicked($event)'>
    </ai-star>


в чем проблема ?

как я могу решить эту проблему ?

 import { Component } from '@angular/core';
import { IProduct } from './Product';
import { ProductFilterPipe } from './product-filter.pipe';
@Component({
    selector: 'pm-products',
    templateUrl: 'app/Product/product-list.component.html',
    pipes: [ProductFilterPipe]
})
export class ProductListComponent {
    pageTitle: string = 'Product List';
    imageWidth: number = 50;
    imageMargin: number = 2;
    listFilter: string = 'cart';
    ShowImage: boolean = false;
    products: IProduct[] = [
        {
            productId: 2,
            productName: "Garden Cart",
            productCode: "GDN-0023",
            releaseDate: "March 18, 2016",
            price: 32.99,
            description: "15 gallon capacity rolling garden cart",
            starRating: 4.2,
            imageUrl: "app/assets/images/garden_cart.png"
        },
        {
            productId: 5,
            productName: "Hammer",
            productCode: "TBX-0048",
            releaseDate: "May 21, 2016",
            description: "Curved claw steel hammer",
            price: 8.9,
            starRating: 4.8,
            imageUrl: "app/assets/images/rejon_Hammer.png"
        }
    ];
    toggleImage(): void {
        this.ShowImage = !this.ShowImage;
    }
}


HTML-код :

<div class='panel panel-default'>
<div class='panel-heading'>
    {{pageTitle}}
</div>
<div class='panel-body'>
    <div class='row'>
        <div class='col-md-2'>Filter by:</div>
        <div class='col-md-4 form-group'>
            <input type='text' class="form-control" [(ngModel)]="listFilter" [ngModelOptions]="{standalone: true}" />
        </div>
    </div>
    <div class='row'>
        <div class='col-md-6'>
            <h3>Filtered by: </h3>
        </div>
    </div>
    <div class='table-responsive'>
        <table class='table' *ngIf='products && products.length'>
            <thead>
                <tr>
                    <th>
                        <button class='btn btn-primary' (click)='toggleImage()'>
                            {{ShowImage ? 'Hide' : 'Show'}} Image
                        </button>
                    </th>
                    <th>Product</th>
                    <th>Code</th>
                    <th>Available</th>
                    <th>Price</th>
                    <th>5 Star Rating</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor='#product of products '>
                    <td>
                        <img *ngIf='ShowImage'

                             [src]='product.imageUrl'

                             [title]='product.productName'

                             [style.width.px]='imageWidth'

                             [style.margin.px]='imageMargin' />
                    </td>
                    <td>{{ product.productName }}</td>
                    <td>{{ product.productCode }}</td>
                    <td>{{ product.releaseDate }}</td>
                    <td>{{ product.price }}</td>
                    <td>
                        <ai-star [rating]='product.starRating'

                                 (ratingClicked)='onRatingClicked($event)'>
                        </ai-star>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>


ProductFilterPip :

   import { PipeTransform, Pipe } from '@angular/core';
import { IProduct } from './Product';

@Pipe({
    name: 'productFilter'
})
export class ProductFilterPipe implements PipeTransform {
    transform(value: IProduct[], args: string): IProduct[] {
        let filter: string = args[0] ? args[0].toLocaleLowerCase() : null;
        return filter ? value.filter((product: IProduct) => product.productName.toLocaleLowerCase().indexOf(filter) != -1) : value;
    }
}


Что я уже пробовал:

в чем проблема ? как я могу решить эту проблему ?

0 Ответов