Skip to content

Commit

Permalink
fix(mat-demo): fix lazy load
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxin committed Sep 13, 2018
1 parent 66748f6 commit 4eec590
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions mat-demo/mat-demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,32 @@ export class MatDemoComponent implements OnInit {
if (!this._opened) {
this._opened = true;

this._init();
this._requestAssets();
}
}

private _init() {
const pathArr = `${this._config.baseUrl}/${this.path}`.split('/').filter(v => !!v);
const pathArr = `${this.path}`.split('/').filter(v => !!v);

if (pathArr.length === 0) {
throw new Error('Invalid path!');
}

const compFilename = pathArr[pathArr.length - 1];
const compPath = '/' + pathArr.join('/');
// default title
this.compName = compFilename.replace(/-(\w)/g, (match, p1) => match && p1.toUpperCase()).replace(/\w/, match => match.toUpperCase());
}

private _requestAssets() {
const pathArr = `${this.path}`.split('/').filter(v => !!v);

if (pathArr.length === 0) {
throw new Error('Invalid path!');
}

const compFilename = pathArr[pathArr.length - 1];
const baseUrl = this._config.baseUrl;
const compPath = baseUrl + (baseUrl[baseUrl.length - 1] === '/' ? '' : '/') + pathArr.join('/');

this.suffixes.forEach(suffix => {
const url = `${compPath}/${compFilename}.component.${suffix}`;
Expand All @@ -75,9 +88,6 @@ export class MatDemoComponent implements OnInit {
this.codes[suffix] = res;
});
});

// default title
this.compName = compFilename.replace(/-(\w)/g, (match, p1) => match && p1.toUpperCase()).replace(/\w/, match => match.toUpperCase());
}
}

0 comments on commit 4eec590

Please sign in to comment.