Class ti shopping cart. Yet another one, icon. Class ti close. The component gets an instance of the service by the means of dependency injection import Component, On. Init fromangularcore. Item from. menu item. Service from. menu. Url. menu. component. Menu. Service. exportclass. Menu. Component. Menu. Item. constructorservice Menu. Service. this. After fetching the Menu. Items from the service the component iterates over them using ng. For and creates the needed markup lt divclasssidebar wrapper. App. Title. lt a. Forlet item of items. Class lt i. Even though this example is quite easy it provides enough stuff to demonstrate the basics of Schematics. Scaffolding a Collection for Schematics. Schematics. To provide a project structure for an npm package with a Schematics Collection, we can leverage Schematics itself. The reason is that the product team provides a meta schematic for this. To get everything up and running we need to install the following npm packages angular devkitschematics for executing Schematicsschematicsschematics for scaffolding a Collectionrxjs which is a needed transitive dependency. For the sake of simplicity, Ive installed them globally npm i g angular devkitschematics. In order to get our collection scaffolded we just need to type in the following command schematics schematicsschematics schematic name nav. The parameter schematicsschematics schematic consists of two parts. Download Psp Fm 2010 Tactics Skate. The first part schematicsschematics is the name of the collection, or to be more precise, the npm package with the collection. The second part schematic is the name of the Schematic we want to use for generating code. After executing this command we get an npm package with a collection that holds three demo schematics The file collection. Each schematic has meta data of its own describing the command line arguments it supports as well as generator code. Usually, they also contain template files with placeholders used for generating code. But more about this in the following sections. Before we can start, we need to npm install the dependencies the generated package. In addition to that, it is a good idea to rename its section dependencies to dev. Dependencies because we dont want to install them when we load the npm package into a project. A schematics. build tsc p tsconfig. MIT. schematics. srccollection. Dependencies. As you saw in the last listing, the packages. Adding an custom Schematic. The three generated schematics contain comments that describe quite well how Schematics works. It is a good idea to have a look at them. For this tutorial, Ive deleted them to concentrate on my own schematic. For this, Im using the following structure The new folder menu contains the custom schematic. Its command line arguments are described by the file schema. The described data structure can also be found as an interface within the file schema. Normally it would be a good idea to generate this interface out of the schema but for this easy case Ive just handwritten it. The index. ts contains the so called factory for the schematic. This is a function that generates a rule containing other rules which describes how the code can be scaffolded. The templates used for this are located in the files folder. We will have a look at them later. First of all, lets update the collection. Generates a menu component. Here we have an property menu for the menu schematic. This is also the name we reference when calling it. The array aliases contains other possible names to use and factory points to the file with the schematics factory. Here, it points to. Thats why the factory is looked up in the file. In addition to that, the collection. This file describes a property for each possible argument. Schemantics. For. Menu. title Menu Schema. Root. type string. Dir. type string. Service. type boolean. Flag to indicate whether an menu service should be generated. The argument name holds the name of the menu component, its path as well as the path of the app app. Root and the src folder source. Dir. These parameters are usually used by all schematics the CLI provides. In addition to that, Ive defined a property menu. Service to indicate, whether the above mentioned service class should be generated too. The interface for the schema within schema. Menu. Options exportinterface. Menu. Options. name string. Root string. path string. Dir string. menu. Service boolean. Schematic Factory. To tell Schematics how to generated the requested code files, we need to provide a factory. This function describes the necessary steps with a rule which normally makes use of further rules import Menu. Options from. schema. Rule,. fromangular devkitschematics. Menu. Options Rule. For this factory, Ive defined two helper constructs at the top of the file import dasherize, classify fromangular devkitcore. Menu. Options from. Rule,. fromangular devkitschematics. Utils dasherize, classify. Templatesoptions Menu. Options Rule. Service. The first one is the object string. Utils which just groups some functions we will need later within the templates The function dasherize transforms a name into its kebab case equivalent which can be used as a file name e.