How to test your component in the playground

Angular Playground is an open source tool to run isolated instances of the components in development that allows to each component take different behaviors, for example a component could be rendered with different style configurations depending of model values. For more information about Angular Playground please visit: http://www.angularplayground.it/arrow-up-right

Minimum Requirements

  1. Angular 6.0.0

  2. Typescript 2.7.0

  3. Angular CLI 6.0.0

Also you need to check if you have the angular-playground package in the package.json. you can install the package with:

npm install --save-dev angular-playground

Create a file in src called main.playground.ts like this:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { PlaygroundModule } from 'angular-playground';

PlaygroundModule
  .configure({
      selector: 'app-root',
      overlay: false,
      modules: []
  });

platformBrowserDynamic().bootstrapModule(PlaygroundModule)
.catch(err => console.log(err));

Add a new file in same path of the package.json called angular-playground.json:

you need to add the project in the angular.json with this configuration:

Finally, update the package.json with the new script:

Create a new component sandbox

To create a new isolated component instance in the Angular Playground you should create a sandbox folder inside the component folder declaration, then you have to create a file with the same name of the component file but ending with .sandbox.tsprefix. After that you can create the sandbox definition as it is shown in the following code sample:

File: label.component.sandbox.ts

Run the playground

Before run the playground, you should compile your project.

Run the next npm command in the package.json root:

Then you can open your browser on http://localhost:4201arrow-up-right

Was this helpful?