这个错误发生在构建后生成的vendor.js中,你能告诉我我做错了吗?
sort.pipe.ts
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({name: 'sortBy'})
export class SortByPipe implements PipeTransform {
transform(array:Array<any>, args:string, args2:string):Array<string> {
array = array || [];
if (array !== undefined) {
array.sort((a:any, b:any) => {
if (args2) {
if (a[args][args2] < b[args][args2]) {
return -1;
} else if (a[args][args2] > b[args][args2]) {
return 1;
} else {
return 0;
}
} else {
if (a[args] < b[args]) {
return -1;
} else if (a[args] > b[args]) {
return 1;
} else {
return 0;
}
}
});
}
return array;
}
}
product.filter.pipe.ts
import {Pipe, PipeTransform} from '@angular/core';
import {Product} from "../service/product.services";
@Pipe({name: 'productFilter'})
export class ProductFilterPipe implements PipeTransform {
transform(products:Product[], text:string):Product[] {
if (products == null || text == null || text.length == 0) {
return products;
}
return products.filter(product => {
return product.id.toString().indexOf(text) >= 0 ||
product.name.toString().toUpperCase().indexOf(text.toUpperCase()) >= 0;
})
}
}
模块
import { ClientFilterPipe } from './shared/pipe/client-filter.pipe';
import { OrderFilterPipe } from './shared/pipe/order-filter.pipe';
import {NgModule} from "@angular/core";
import {ChartsModule} from "ng2-charts/ng2-charts";
import {OrderComponent} from "./order/order.component";
import {DashboardRoutingModule} from "./dashboard-routing.module";
import {ClientComponent} from "./client/client.component";
import {ProductComponent} from "./product/product.component";
import { ModalModule } from 'ng2-bootstrap/modal';
import {OrderService} from './shared/service/order.service'
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { TextMaskModule } from 'angular2-text-mask';
import {ProductFilterPipe} from "./shared/pipe/product-filter.pipe";
import {SortByPipe} from "./shared/pipe/sort.pipe";
import { SharedModule } from "app/shared/shared.module";
@NgModule({
imports: [
CommonModule,
FormsModule,
DashboardRoutingModule,
ChartsModule,
TextMaskModule,
ModalModule.forRoot(),
SharedModule
],
declarations: [
OrderComponent,
ClientComponent,
ProductComponent,
ProductFilterPipe,
OrderFilterPipe,
ClientFilterPipe,
SortByPipe
],
providers: [
OrderService
]
})
export class DashboardModule {
}
html标记
<tr *ngFor="let product of (AllProducts | productFilter:textSearch | sortBy:ordination)">
的package.json
"dependencies": {
"@angular/common": "2.4.9",
"@angular/compiler": "2.4.9",
"@angular/core": "2.4.9",
"@angular/forms": "2.4.9",
"@angular/http": "2.4.9",
"@angular/platform-browser": "2.4.9",
"@angular/platform-browser-dynamic": "2.4.9",
"@angular/router": "3.4.9",
"@angular/upgrade": "2.4.9",
"angular2-text-mask": "^8.0.0",
"chart.js": "2.5.0",
"core-js": "2.4.1",
"moment": "2.17.1",
"ng2-bootstrap": "1.4.0",
"ng2-charts": "1.5.0",
"rxjs": "5.2.0",
"ts-helpers": "1.1.2",
"zone.js": "0.7.2"
},
"devDependencies": {
"@angular/cli": "^1.1.2",
"@angular/compiler-cli": "2.4.9",
"@types/jasmine": "2.5.45",
"@types/node": "7.0.8",
"codelyzer": "2.0.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.5.0",
"karma-chrome-launcher": "2.0.0",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "0.3.0",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "0.2.2",
"protractor": "5.1.1",
"ts-node": "2.1.0",
"tslint": "4.5.1",
"typescript": "2.2.1"
}
ERRO
未捕获的TypeError:t.sort不是函数 在t.transform(1.c084fff4f7c75c6a444a.chunk.js:格式:266) 在vendor.d076f160cfb2a88c98b2.bundle.js:1 在proxyViewClass.View_t0.detectChangesInternal(VM3772 component.ngfactory.js:1815) 在proxyViewClass.t.detectChanges(vendor.d076f160cfb2a88c98b2.bundle.js:1) 在proxyViewClass.t.internalDetectChanges(vendor.d076f160cfb2a88c98b2.bundle.js:1) 在proxyViewClass.View_t_Host0.detectChangesInternal(VM3775 host.ngfactory.js:33) 在proxyViewClass.t.detectChanges(vendor.d076f160cfb2a88c98b2.bundle.js:1) at t.detectChangesInNestedViews(vendor.d076f160cfb2a88c98b2.bundle.js:1) 在proxyViewClass.View_e0.detectChangesInternal(VM3721 component.ngfactory.js:199) 在proxyViewClass.t.detectChanges(vendor.d076f160cfb2a88c98b2.bundle.js:1) 在proxyViewClass.t.internalDetectChanges(vendor.d076f160cfb2a88c98b2.bundle.js:1) 在proxyViewClass.View_e_Host0.detectChangesInternal(VM3723 host.ngfactory.js:27) 在proxyViewClass.t.detectChanges(vendor.d076f160cfb2a88c98b2.bundle.js:1) at t.detectChangesInNestedViews(vendor.d076f160cfb2a88c98b2.bundle.js:1) 在proxyViewClass.View_anonymous_00.detectChangesInternal(/anonymous_1/anonymous_0/component.ngfactory.js:27)