Reader small image

You're reading from  Expert Angular

Product typeBook
Published inJul 2017
Reading LevelExpert
PublisherPackt
ISBN-139781785880230
Edition1st Edition
Languages
Right arrow
Author (1)
Sridhar Rao Chivukula
Sridhar Rao Chivukula
author image
Sridhar Rao Chivukula

Sridhar Rao Chivukula is a technical lead at Mindtree Ltd and is based out of New York City. He brings with him more than a decade of rich hands-on experience in all aspects of frontend engineering. He has worked with leading companies such as Oracle, Tech Mahindra, and Cognizant Technology Solutions. He has a Bachelor's degree in Information Technology. He is the author of the books Expert Angular and PHP and Web 2.0 Application Interfaces, published by Packt.
Read more about Sridhar Rao Chivukula

Right arrow

Generating directives and pipes

A class decorated with @Directive to attach metadata is called a directive. It is an instruction or guideline to render the template.

We have seen generating components and services. Now, let's generate directives and pipes using Angular CLI. We will start with creating a directive named book. Run the following command to generate the directive:

ng generate directive book       

The outcome of executing the command is shown here:

Executing this command creates two files, namely, book.directive.spec.ts and book.directive.ts respectively. Here is the code snippet of book.directive.ts:

import { Directive } from '@angular/core';
@Directive({
selector: '[appBookish]'
})
export class BookishDirective {
constructor() { }
}

The code snippet of book.directive.spec.ts is shown here:

/* tslint:disable:no-unused...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Expert Angular
Published in: Jul 2017Publisher: PacktISBN-13: 9781785880230

Author (1)

author image
Sridhar Rao Chivukula

Sridhar Rao Chivukula is a technical lead at Mindtree Ltd and is based out of New York City. He brings with him more than a decade of rich hands-on experience in all aspects of frontend engineering. He has worked with leading companies such as Oracle, Tech Mahindra, and Cognizant Technology Solutions. He has a Bachelor's degree in Information Technology. He is the author of the books Expert Angular and PHP and Web 2.0 Application Interfaces, published by Packt.
Read more about Sridhar Rao Chivukula