|
| 1 | +import { Component, OnDestroy, OnInit } from '@angular/core'; |
1 | 2 | import { DevuiSourceData } from 'ng-devui/shared/devui-codebox/devui-source-data';
|
2 |
| -import { Component } from '@angular/core'; |
| 3 | +import { TranslateService, TranslationChangeEvent } from '@ngx-translate/core'; |
| 4 | +import { Subscription } from 'rxjs'; |
3 | 5 | @Component({
|
4 | 6 | selector: 'd-accordion-demo',
|
5 | 7 | templateUrl: './accordion-demo.component.html',
|
6 | 8 | })
|
7 |
| -export class AccordionDemoComponent { |
| 9 | +export class AccordionDemoComponent implements OnInit, OnDestroy { |
8 | 10 | AccordionDemoBasic: Array<DevuiSourceData> = [
|
9 |
| - {title: 'HTML', language: 'xml', code: require('!!raw-loader!./basic/basic.component.html')}, |
10 |
| - {title: 'TS', language: 'typescript', code: require('!!raw-loader!./basic/basic.component.ts')}, |
11 |
| - {title: 'SCSS', language: 'css', code: require('!!raw-loader!./basic/basic.component.css')} |
| 11 | + { title: 'HTML', language: 'xml', code: require('!!raw-loader!./basic/basic.component.html') }, |
| 12 | + { title: 'TS', language: 'typescript', code: require('!!raw-loader!./basic/basic.component.ts') }, |
| 13 | + { title: 'SCSS', language: 'css', code: require('!!raw-loader!./basic/basic.component.css') }, |
12 | 14 | ];
|
13 | 15 |
|
14 | 16 | AccordionDemolink: Array<DevuiSourceData> = [
|
15 |
| - {title: 'HTML', language: 'xml', code: require('!!raw-loader!./link/link.component.html')}, |
16 |
| - {title: 'TS', language: 'typescript', code: require('!!raw-loader!./link/link.component.ts')}, |
17 |
| - {title: 'SCSS', language: 'css', code: require('!!raw-loader!./link/link.component.css')} |
| 17 | + { title: 'HTML', language: 'xml', code: require('!!raw-loader!./link/link.component.html') }, |
| 18 | + { title: 'TS', language: 'typescript', code: require('!!raw-loader!./link/link.component.ts') }, |
| 19 | + { title: 'SCSS', language: 'css', code: require('!!raw-loader!./link/link.component.css') }, |
18 | 20 | ];
|
19 | 21 |
|
20 | 22 | AccordionDemoTemplate: Array<DevuiSourceData> = [
|
21 |
| - {title: 'HTML', language: 'xml', code: require('!!raw-loader!./template/template.component.html')}, |
22 |
| - {title: 'TS', language: 'typescript', code: require('!!raw-loader!./template/template.component.ts')}, |
23 |
| - {title: 'SCSS', language: 'css', code: require('!!raw-loader!./template/template.component.scss')} |
| 23 | + { title: 'HTML', language: 'xml', code: require('!!raw-loader!./template/template.component.html') }, |
| 24 | + { title: 'TS', language: 'typescript', code: require('!!raw-loader!./template/template.component.ts') }, |
| 25 | + { title: 'SCSS', language: 'css', code: require('!!raw-loader!./template/template.component.scss') }, |
24 | 26 | ];
|
25 | 27 |
|
26 | 28 | AccordionDemoInnerListTemplate: Array<DevuiSourceData> = [
|
27 |
| - {title: 'HTML', language: 'xml', |
28 |
| - code: require('!!raw-loader!./inner-list-template/inner-list-template.component.html')}, |
29 |
| - {title: 'TS', language: 'typescript', |
30 |
| - code: require('!!raw-loader!./inner-list-template/inner-list-template.component.ts')}, |
31 |
| - {title: 'SCSS', language: 'css', code: require('!!raw-loader!./inner-list-template/inner-list-template.component.css')} |
| 29 | + { title: 'HTML', language: 'xml', code: require('!!raw-loader!./inner-list-template/inner-list-template.component.html') }, |
| 30 | + { title: 'TS', language: 'typescript', code: require('!!raw-loader!./inner-list-template/inner-list-template.component.ts') }, |
| 31 | + { title: 'SCSS', language: 'css', code: require('!!raw-loader!./inner-list-template/inner-list-template.component.css') }, |
32 | 32 | ];
|
33 | 33 | AccordionDemoMultiLevel: Array<DevuiSourceData> = [
|
34 |
| - {title: 'HTML', language: 'xml', |
35 |
| - code: require('!!raw-loader!./multi-level/multi-level.component.html')}, |
36 |
| - {title: 'TS', language: 'typescript', |
37 |
| - code: require('!!raw-loader!./multi-level/multi-level.component.ts')}, |
38 |
| - {title: 'SCSS', language: 'css', code: require('!!raw-loader!./multi-level/multi-level.component.css')} |
| 34 | + { title: 'HTML', language: 'xml', code: require('!!raw-loader!./multi-level/multi-level.component.html') }, |
| 35 | + { title: 'TS', language: 'typescript', code: require('!!raw-loader!./multi-level/multi-level.component.ts') }, |
| 36 | + { title: 'SCSS', language: 'css', code: require('!!raw-loader!./multi-level/multi-level.component.css') }, |
39 | 37 | ];
|
40 | 38 | AccordionDemoChangeKey: Array<DevuiSourceData> = [
|
41 |
| - {title: 'HTML', language: 'xml', |
42 |
| - code: require('!!raw-loader!./change-key/change-key.component.html')}, |
43 |
| - {title: 'TS', language: 'typescript', |
44 |
| - code: require('!!raw-loader!./change-key/change-key.component.ts')}, |
45 |
| - {title: 'SCSS', language: 'css', code: require('!!raw-loader!./change-key/change-key.component.css')} |
46 |
| - ]; |
47 |
| - navItems = [ |
48 |
| - { dAnchorLink: 'basic-usage', value: '基本用法'}, |
49 |
| - { dAnchorLink: 'use-built-in-routing-and-link-types', value: '内置路由和链接类型'}, |
50 |
| - { dAnchorLink: 'using-templates', value: '使用模板'}, |
51 |
| - { dAnchorLink: 'compound-level-and-auto-expand', value: '复合层级和自动展开'}, |
52 |
| - { dAnchorLink: 'change-values', value: '改变键值'} |
| 39 | + { title: 'HTML', language: 'xml', code: require('!!raw-loader!./change-key/change-key.component.html') }, |
| 40 | + { title: 'TS', language: 'typescript', code: require('!!raw-loader!./change-key/change-key.component.ts') }, |
| 41 | + { title: 'SCSS', language: 'css', code: require('!!raw-loader!./change-key/change-key.component.css') }, |
53 | 42 | ];
|
| 43 | + |
| 44 | + navItems = []; |
| 45 | + subs: Subscription = new Subscription(); |
| 46 | + constructor(private translate: TranslateService) {} |
| 47 | + |
| 48 | + ngOnInit() { |
| 49 | + this.subs.add( |
| 50 | + this.translate.get('components.accordion.anchorLinkValues').subscribe((res) => { |
| 51 | + this.setNavValues(res); |
| 52 | + }) |
| 53 | + ); |
| 54 | + |
| 55 | + this.subs.add( |
| 56 | + this.translate.onLangChange.subscribe((event: TranslationChangeEvent) => { |
| 57 | + const values = this.translate.instant('components.accordion.anchorLinkValues'); |
| 58 | + this.setNavValues(values); |
| 59 | + }) |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + setNavValues(values) { |
| 64 | + this.navItems = [ |
| 65 | + { dAnchorLink: 'basic-usage', value: values['basic-usage'] }, |
| 66 | + { dAnchorLink: 'use-built-in-routing-and-link-types', value: values['use-built-in-routing-and-link-types'] }, |
| 67 | + { dAnchorLink: 'using-templates', value: values['using-templates'] }, |
| 68 | + { dAnchorLink: 'compound-level-and-auto-expand', value: values['compound-level-and-auto-expand'] }, |
| 69 | + { dAnchorLink: 'change-values', value: values['change-values'] }, |
| 70 | + ]; |
| 71 | + } |
| 72 | + |
| 73 | + ngOnDestroy() { |
| 74 | + if (this.subs) { |
| 75 | + this.subs.unsubscribe(); |
| 76 | + } |
| 77 | + } |
54 | 78 | }
|
0 commit comments