Skip to content

Instantly share code, notes, and snippets.

@Manbearpixel
Created April 4, 2019 09:31
Show Gist options
  • Save Manbearpixel/2b288b3f2e456611b00d4ea483eb957d to your computer and use it in GitHub Desktop.
Save Manbearpixel/2b288b3f2e456611b00d4ea483eb957d to your computer and use it in GitHub Desktop.
RadListView--Example--MultipleTemplates--Component
import { Component } from '@angular/core';
class User {
// These properties are publicly exposed
public name: string;
public status: string;
// Accept an optional name and status when being instantiated
constructor(name?: string, status?: string) {
this.name = name ? name : 'Default Name';
this.status = status ? status : '';
}
}
@Component({
moduleId: module.id,
selector: 'example',
templateUrl: './radlistview-multipletemplates.html',
styleUrls: []
})
export class RadListViewMultipleTemplatesComponent {
// Define the array of Users which should be publicly exposed
public userCollection: User[];
constructor() {
this.userCollection = [
new User('The Boss', 'admin'),
new User('The User', 'basic'),
new User('The Unknown')
];
}
/**
* Template rendering method to help determine which template to load for a given
* `User`.
*
* @param item The `User` model
* @param index The index of the item
* @param items The array of items
*/
public userCollectionTemplateSwitch(item: User, index: number, items: any): string {
return item.status;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment