Skip to content

Commit 0dc87af

Browse files
author
Stijn Goethals
committed
add custom array collection #11
1 parent c308f48 commit 0dc87af

File tree

7 files changed

+61
-30
lines changed

7 files changed

+61
-30
lines changed

src/app/app.component.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div {
2+
margin-bottom: 10px;
3+
}

src/app/app.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ <h1>ng-select2 demo's</h1>
1212
<app-dynamic></app-dynamic>
1313
<hr>
1414
<app-multiple></app-multiple>
15-
</div>
15+
<hr>
16+
<app-custom-array></app-custom-array>
17+
</div>

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { MultipleComponent } from './demos/multiple/multiple.component';
1111
import { TemplateComponent } from './demos/template/template.component';
1212
import { DataService } from './services/data.service';
1313
import { FormsModule } from '@angular/forms';
14+
import { CustomArrayComponent } from './demos/custom-array/custom-array.component';
1415

1516

1617
@NgModule({
@@ -21,7 +22,8 @@ import { FormsModule } from '@angular/forms';
2122
ChangeComponent,
2223
DynamicComponent,
2324
TemplateComponent,
24-
MultipleComponent
25+
MultipleComponent,
26+
CustomArrayComponent
2527
],
2628
imports: [
2729
BrowserModule,

src/app/demos/custom-array/custom-array.component.css

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h2>7. Custom array</h2>
2+
<ng-select2 [data]="exampleData"
3+
[width]="300"
4+
[options]="options">
5+
</ng-select2>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Options } from 'select2';
3+
4+
@Component({
5+
selector: 'app-custom-array',
6+
templateUrl: './custom-array.component.html',
7+
styleUrls: ['./custom-array.component.css']
8+
})
9+
export class CustomArrayComponent implements OnInit {
10+
public exampleData: any[];
11+
public options: Options;
12+
13+
ngOnInit() {
14+
this.exampleData = [
15+
{
16+
id: 'basic1',
17+
custom: { en: 'Label 1' }
18+
},
19+
{
20+
id: 'basic2',
21+
disabled: true,
22+
custom: { en: 'Label 2' }
23+
},
24+
{
25+
id: 'basic3',
26+
custom: { en: 'Label 3' }
27+
},
28+
{
29+
id: 'basic4',
30+
custom: { en: 'Label 4' }
31+
}
32+
];
33+
34+
this.options = {
35+
multiple: true,
36+
theme: 'classic',
37+
closeOnSelect: false,
38+
width: '300',
39+
templateSelection: (object: any) => {
40+
return object && object.custom && object.custom.en;
41+
},
42+
templateResult: (object: any) => {
43+
return object && object.custom && object.custom.en;
44+
}
45+
};
46+
}
47+
}

src/app/demos/options/options.component.spec.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)