Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
MEAN Cookbook
MEAN Cookbook

MEAN Cookbook: The meanest set of MEAN stack solutions around

eBook
₱579.99 ₱2000.99
Paperback
₱2500.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

MEAN Cookbook

Enhancing Your User Interface

This chapter will provide recipes for common user interface enhancements in your single app web application using Angular. We will learn to use Sass to control the styling of our application as well as importing common user interface tools such as the Bootstrap & Font-Awesome to our application. We'll also cover the basics of internalizing our user interface in Angular-CLI with it's built-in i18n toolkit.

In this chapter, we will cover the following recipes :

  • Configuring Sass for Angular
  • Working with Angular component styles
  • Using Sass variables for style reusability
  • Using Sass nesting for better style specificity
  • Importing Sass partials for style organization
  • Working with Bootstrap in Sass
  • Customizing Bootstrap for Angular
  • Using Bootstrap Responsive layouts
  • Working with Bootstrap components in Angular
  • Working with Font-Awesome icons...

Introduction

Building a modern web application with Angular involves adding some sort of CSS framework to your application. CSS provides a robust and rich set of styling options to manage the look and feel of your web application. However, in many respects, vanilla CSS provides us with only the very basics to build modern, maintainable styles for our web applications. Luckily, similar to the advancements made in JavaScript compilation, there has been a revolution in CSS-based pre-compilers that add many useful enhancements and features to the CSS standard.

In this chapter we will cover common CSS configurations for Angular, including how to use the most popular CSS preprocessor, Sass. We will also take a look at a variety of ways we can use Sass that is unique to working within Angular-CLI that can streamline our frontend development productivity.

...

Configuring Sass in Angular

Angular-CLI supports all the major CSS preprocessors, including Sass, Less, and Stylus. Although each of these options has its own unique features and language syntax, Sass is, by far, the most popular CSS preprocessor used for web applications. For that reason it is what we will focus on in this book.

Sass works as as superset to CSS in a similar way that TypeScript acts as a superset of JavaScript in Angular. Our Sass styles will compile during our Angular-CLI build process, and output vanilla CSS for the browser. It will also allow us to use many useful features, such as defining variables, nesting for selectors for improved specificity, and better organizing our styles for reusable and composable styling.

Getting ready

...

Working with Angular component styles

Angular has a unique way of isolating styles on components in our application by scoping CSS selectors to dynamically generated component selectors. This approach gives us component-level style isolation that will prevent our component's styles from leaking across the rest of our application.

Let's add some component styles to our /src/app/app.component.ts and /src/app/posts/posts.component.ts components. We'll give our header some padding between it and the blog content below it. Adding negative space to our user interface like this will make our blog content easier to read. We will frame the blog content itself with a border and a silver background color.

How to do it...

...

Using Sass variables for style reusability

A very handy advantage of using Sass is to define commonly used values in our styles as variables so that they can be easily reused in our project's styling.

Imagine that our Angular application has a very simple two-color theme for its background and text. For our navigation, we simply want to reverse the same two colors of theme for the background and text. With Sass, we can define these colors once and then apply them to the correct properties for the objects we want to style, without copying and pasting hexadecimal color definitions around.

How to do it...

We can define two-color variables by defining them in our /src/styles.scss stylesheet:

$background-color: #585858;
$text...

Using Sass nesting for better style specificity

Another advantage of Sass is the ability to nest selectors to increase their styling specificity, as well as make relationships between content styles more manageable. Sass's ability to nest selectors helps enforce selector specificity through a clear visual relationship with its parent selectors. This makes creating style hierarchies in your application much more visually apparent in the stylesheet itself.

Getting ready

Imagine that we have two styles of links, one that is for our general content and another that is, specifically, for our navigation. We really want to be certain that these links are styled the same way, except for their coloring. We could write these as...

Using Sass partials for style organization

Sass has more features than just its advanced CSS syntax and language features. It also allows us to more easily modularize our styles into partials for easier reuse and configuration. The modularization aspect of Sass partials is one of the most powerful features for organizing and maintaining your app's styling.

Getting ready

Let's make the color definitions for our web application's Sass variables a separate configuration file from our other Sass files. This will make updating our branding or any other color configuration changes much easier to find and make in our application.

...

Working with Bootstrap in Sass

In this section, we will discuss how to import CSS frameworks and utilities into our application to set up a basic, responsive layout in our Angular application using Bootstrap. Bootstrap is a very popular CSS framework developed by Twitter for responsive web design that works on a wide range of devices, from desktop computers to mobile phones. The latest version of Bootstrap 4 includes many improvements, including switching from Less to Sass for its source files, a new flex-box-based grid system, and many optimizations and performance tweaks to better support mobile devices.

How to do it...

Our Angular application may be modern on the inside, but its user interface is very retro looking, without...

Customizing Bootstrap for Angular

Configuring Bootstrap will let you customize the parts of the Bootstrap framework you include in your application. Loading fewer parts of Bootstrap will reduce your file size, thus, increasing the performance of compiling your Sass stylesheets.

Getting ready

Loading all of Bootstrap is great, but what if we don't want or need all of the Bootstrap framework in our Angular application? Let's remove all the built-in JavaScript components used by Bootstrap so that we can implement our own Angular-based versions instead.

How to do it...

...

Using Bootstrap Responsive layouts

One of the best reasons to use a CSS framework such as Bootstrap is to more easily support responsive layouts in our web application. Using Bootstrap's layout classes and breakpoints, we can easily add responsive design to our Angular application.

Getting ready

Bootstrap 4 supports a modern flex-box-based responsive grid system. To use the grid system, we will need to declare a container that will contain the grid, rows for each line of elements we will lay out in the container, and columns for each item in the row:

>

We can compose any combination of column widths together that we want as long as the total within the row adds up to 12 or fewer. Otherwise our column content will...

Working with Bootstrap components in Angular

Bootstrap 4 contains many different JavaScript-dependent components. Many of these components rely on jQuery for Document Object Model (DOM) manipulation and can adversely interact with Angular's own View Encapsulation based data-binding. We will solve this issue using the Angular-friendly versions of these components provided by the ng-bootstrap project.

Getting ready

Let's add an accordion component to our web application, so we can group blog posts by their author. When the user clicks on the author's name, they will see a list of blog posts they created.

In order to build this functionality, we will need to install and save the ng-bootstrap project as a dependency...

Working with Font-Awesome icons in Angular

Unlike the preceding version of Bootstrap, Bootstrap 4 does not come with a built-in icon set. You get to choose the icon set you'd like to include for your application.

The Font-Awesome project is a very popular font-based icon set with a robust collection of high-quality icons that cover a wide range of common application functionalities, all available for free as an open source resource.

Getting ready

Let's enhance our new Bootstrap accordion component by putting a user icon next to all our author's names and a newspaper icon next to their blog post titles. Before we can get started, we will need to install font-awesome as a dependency to our project. We will do...

Internationalization with Angular i18n

Modern web applications can often support millions of users distributed across the globe. Even if the audience for your application is limited, the advantages you gain from building an application supporting multiple languages or localized date and time formatting can be very important for any international customers who use it. Luckily, Angular has an advanced toolkit for managing translations and localizing content in our application.

To translate text files in Angular, we will use the i18n attribute that comes built-in with Angular core. We will use this tool to mark strings in our application for translation and run a utility in Angular-CLI to extract them. Once we've extracted the strings, we can hand them off as a static file to be translated, and we will be able to import this file to display a localized language version of our...

Setting your language with Angular i18n

Although ahead-of-time (AOT) compilation of template strings can be useful, users may often wish to be able to manually decide the language that they would like to see, and have that served to them as a just-in-time (JIT) option. To support this, we will need to add providers to Angular to watch for a locale setting we can use to determine our user's language preference.

Let's configure our application to display whatever language the browser is defaulted to using. That way, content will automatically be displayed in any translation that matches the machine that they are using to access our application.

Getting ready

Before we can get started, to take advantage of just-in-time...

How to Localize dates in Angular

Many countries format dates and times in a different way. For example, between the US and UK, the order of months and days is often reversed in shortened dates. For example, 12/5/2017 is December 5th, 2017 (MM/DD/YYYY) in the US, while it would mean May 12th, 2017 (DD/MM/YYYY). Unlocalized date format can be potentially very confusing to your users and is an easy localization option offered by Angular's built-in Pipes helper.

How to do it...

Let's follow the steps to add date localization to our blog posts so that they will display in the format our readers would expect:

  1. We'll start by adding a simple date object to our /src/app/posts/post/post.component.ts component:
postDate...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Architect a fully functional stand-alone web application, including the web server, database, and front-end web application
  • Improve the performance and maintainability of your MEAN stack application with tips for configuration and optimization
  • Highlights MEAN Stack best practices when working with your application

Description

The MEAN Stack is a framework for web application development using JavaScript-based technologies; MongoDB, Express, Angular, and Node.js. If you want to expand your understanding of using JavaScript to produce a fully functional standalone web application, including the web server, user interface, and database, then this book can help guide you through that transition. This book begins by configuring the frontend of the MEAN stack web application using the Angular JavaScript framework. We then implement common user interface enhancements before moving on to configuring the server layer of our MEAN stack web application using Express for our backend APIs. You will learn to configure the database layer of your MEAN stack web application using MongoDB and the Mongoose framework, including modeling relationships between documents. You will explore advanced topics such as optimizing your web application using WebPack as well as the use of automated testing with the Mocha and Chai frameworks. By the end of the book, you should have acquired a level of proficiency that allows you to confidently build a full production-ready and scalable MEAN stack application.

Who is this book for?

If you are a JavaScript developer who wants to create high-performing, modern web applications with the MEAN stack, this is the book for you. Web developers familiar with some parts of the MEAN stack will find this a comprehensive guide to fleshing out the other technologies and skills they need to build all JavaScript web applications. Developers interested in transitioning from other web application stacks to an all-JavaScript environment will find a wealth of information about how to work in a MEAN stack environment. To get the most from this book, you should have a general understanding of web servers and web applications. You are expected to have a basic understanding of running JavaScript, both in a web browser and outside it, using Node.js and the NPM package manager.

What you will learn

  • • Bootstrap a new MEAN stack web application using Node.js and Express
  • • Build a single-page application (SPA) with Angular and Angular-CLI
  • • Improve browser performance by optimizing your web application resources using Webpack
  • • Model complex JSON object relationships in MongoDB using Mongoose
  • • Debug all the layers of a MEAN stack application, including working with source maps
  • • Build Restful APIs using Express.js and JSON Web Token (JWT) for user authentication
  • • Use automated testing to improve the reliability and quality of your MEAN stack application
Estimated delivery fee Deliver to Philippines

Standard delivery 10 - 13 business days

₱492.95

Premium delivery 5 - 8 business days

₱2548.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 28, 2017
Length: 450 pages
Edition : 1st
Language : English
ISBN-13 : 9781787286573
Vendor :
Google
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Philippines

Standard delivery 10 - 13 business days

₱492.95

Premium delivery 5 - 8 business days

₱2548.95
(Includes tracking information)

Product Details

Publication date : Sep 28, 2017
Length: 450 pages
Edition : 1st
Language : English
ISBN-13 : 9781787286573
Vendor :
Google
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 8,114.97
MEAN Cookbook
₱2500.99
Mastering  Node.js
₱2806.99
Node Cookbook
₱2806.99
Total 8,114.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Working with Angular 4 Chevron down icon Chevron up icon
Enhancing Your User Interface Chevron down icon Chevron up icon
Working with Data Chevron down icon Chevron up icon
Using Express Web Server Chevron down icon Chevron up icon
REST APIs and Authentication Chevron down icon Chevron up icon
Cloud Service Integrations Chevron down icon Chevron up icon
MongoDB and Mongoose Chevron down icon Chevron up icon
Relationships Chevron down icon Chevron up icon
Build Systems and Optimizations Chevron down icon Chevron up icon
Debugging Chevron down icon Chevron up icon
Automated Testing Chevron down icon Chevron up icon
Whats new in Angular 4 Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(1 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
John A Feb 13, 2020
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I was hoping to just ignore the angular section as I am a react developer but it is all so wrapped around angular I struggled with all sections, a mern version of this book would be ideal
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela