Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 9c78345

Browse files
amcdnljelbourn
authored andcommitted
fix(stackblitz): fix dialogs not working #5899 #228 #8750 (#356)
1 parent ab7505f commit 9c78345

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/app/shared/stackblitz/stackblitz-writer.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,30 @@ export class StackblitzWriter {
153153
fileContent = fileContent.replace(/{{version}}/g, VERSION.full);
154154
} else if (fileName == 'main.ts') {
155155
// Replace the component name in `main.ts`.
156-
// For example, `import {MaterialDocsExample} from 'material-docs-example'`
156+
// Replace `import {MaterialDocsExample} from 'material-docs-example'`
157157
// will be replaced as `import {ButtonDemo} from './button-demo'`
158-
fileContent = fileContent.replace(/MaterialDocsExample/g, data.componentName);
158+
fileContent = fileContent.replace(/{MaterialDocsExample}/g, `{${data.componentName}}`);
159+
160+
// Replace `declarations: [MaterialDocsExample]`
161+
// will be replaced as `declarations: [ButtonDemo]`
162+
fileContent = fileContent.
163+
replace(/declarations: \[MaterialDocsExample\]/g,
164+
`declarations: [${data.componentName}]`);
165+
166+
// Replace `entryComponents: [MaterialDocsExample]`
167+
// will be replaced as `entryComponents: [DialogContent]`
168+
fileContent = fileContent.
169+
replace(/entryComponents: \[MaterialDocsExample\]/g,
170+
`entryComponents: [${data.componentName}]`);
171+
172+
// Replace `bootstrap: [MaterialDocsExample]`
173+
// will be replaced as `bootstrap: [ButtonDemo]`
174+
// This assumes the first component listed in the main component
175+
const componentList = data.componentName.split(',')[0];
176+
fileContent = fileContent.
177+
replace(/bootstrap: \[MaterialDocsExample\]/g,
178+
`bootstrap: [${componentList}]`);
179+
159180
fileContent = fileContent.replace(/material-docs-example/g, data.indexFilename);
160181
}
161182
return fileContent;

src/assets/stackblitz/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import {CdkTableModule} from '@angular/cdk/table';
8080
export class DemoMaterialModule {}
8181

8282
@NgModule({
83-
8483
imports: [
8584
BrowserModule,
8685
BrowserAnimationsModule,
@@ -90,7 +89,7 @@ export class DemoMaterialModule {}
9089
MatNativeDateModule,
9190
ReactiveFormsModule,
9291
],
93-
92+
entryComponents: [MaterialDocsExample],
9493
declarations: [MaterialDocsExample],
9594
bootstrap: [MaterialDocsExample],
9695
providers: []

0 commit comments

Comments
 (0)