I\'ve written a construct similar to the following in an Angular app (this has been greatly simplified to demonstrate the issue). What would prevent the filte
I was able to get it working the way I had originally wanted it to with the below setup. The key was, apparently, adding a filter property to the C# object that was being used to serialize data to JSON via Web API. Not sure why this would be required, as TypeScript should be able to extend the model received from Web API with additional functionality.
Example simplified to demonstrate the problem set
DemoModel.cs
// C# Class JSON is serialized from via Web API
public class DemoModel
{
public string displayName { get; set; }
public string filter
{
get { return displayName; }
}
}
iproperty.interface.ts
export interface IProperty {
filter: string;
}
demo.model.ts
import { IProperty } from '../interfaces/iproperty.interface';
export class Demo implements IProperty {
displayName: string;
get filter(): string { return this.displayName; }
}
core.datasource.ts
export class CoreDataSource {
filterChange = new BehaviorSubject('');
filteredData: TItem[];
get filter(): string { return this.filterChange.value; }
set filter(filter: string) { this.filterChange.next(filter); }
constructor(private service: IService) {
super();
this.filteredData = service.data.value.slice();
}
connect(): Observable {
const displayDataChanges = [
this.service.data,
this.filterChange
];
return Observable.merge(...displayDataChanges).map(() => {
this.filteredData = this.service.data.value.slice().filter((item: TItem) => {
const searchStr = item.filter.toLowerCase();
return searchStr.indexOf(this.filter.toLowerCase()) !== -1;
});
return filteredData;
});
}
}