What’s new in Angular CLI 8.1?

Angular CLI 8.1 is released with lot of interesting changes.

This release includes brand new options for the various commands.

The official Node.js version that is supported for Angular CLI 8.0+ is 10.9 or greater.

Flag !

Lets look into the latest updates related to flags.

ng doc

It helps to open the official documentation in browser from CLI and also searched for given keyword.

For example, if you need to search for pipes relates documentation by passing pipes as keyword in ng doc command.

ng doc pipes

This will help us to open the related documentation in browser.

ng doc <keyword> –search

we additionally have the following options to this command

ng doc pipes --search=true|false

When search option is true, searches all of angular.io. Otherwise, searches only API reference documentation. Default: false

The similar option can simplified with alias -s as following

ng doc pipes --s=true

The command needs to be ran inside a angular project definition. Otherwise, we will get following error message in CLI

The doc command requires to be run in an Angular project, but a project definition could not be found.

ng doc pipes -s=false

ng doc pipes -s=true

You can compare difference search option flag values in above couple of images.

The command now also allows us to search for particular version of documents.

For example, we can search for documents related forms in angular version 6 using following command

ng doc form -s=false --version 6

If we didn’t specify any version during search, the command will search angular version you are using in your project.

ng generate component – -skip-selector

CLI version 8.1 brings an option to generate a component without any selectors.

--skip-selector

For example, the following command generates a component with selector

ng generate component sidebar

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-sidebar',
  templateUrl: './sidebar.component.html',
  styleUrls: ['./sidebar.component.css']
})
export class SidebarComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

whereas, the following command with skip selector generates a component without selector

ng generate component sidebar-ws –skip-selector

import { Component, OnInit } from '@angular/core';

@Component({
  templateUrl: './sidebar-ws.component.html',
  styleUrls: ['./sidebar-ws.component.css']
})
export class SidebarWsComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

This new flag will be helpful when we are dealing with situation to create a component which doesn’t actually required a component.

Simple example, consider we need to redirect to error page when something went wrong in application. In that case, we simply redirect the page to specific component with help routing.

Thanks for reading. Please feel free to subscribe, share and support this blog.

Join 1,078 other followers
Advertisement

ASP.NET Core 2.2.0-preview1 – Web templates update

The first preview of the next minor release of ASP.NET Core and .NET Core is available from Aug 21, 2018. The new .NET Core SDK of 2.2.0-preview1 can be downloaded from here.

We need Preview of Visual Studio 2017 – 15.9 Preview 1 to work with .NET Core 2.2 projects.

Whats new in 2.2?

.NET Core listed the following features in their documentation. Now, there is no much information regarding the features in details. They will be publishing detailed information about features soon and hyperlinking that documentation in the same release page.

The new features have been discussed in the ASP.NET Community Standup call.

 

In this post, I would like to discuss updated web templates. Even though we need Visual Studio Preview to work with ASP.NET Core Projects. I have used VS Code to discuss the web templates in this post.

Current Version

Before upgrading the SDK, I wanted to check the current version of the .NET Core with the command.


dotnet --version

version

We can download the .NET Core 2.2 SDK from the link,

https://www.microsoft.com/net/download/dotnet-core/2.2

We can download and start Installation based on our system environment.

SDK

Once installed we can check whether the latest version is available or not with the same command which we have earlier in this post.

SDK2

Now, dotnet version is updated the 2.2.1 preview 🙂

Let’s create a web application

Using dotnet CLI, we can create the application from the command prompt right away. Following is the syntax to create an application


dotnet new  [--force] [-i|--install] [-lang|--language] [-n|--name] [--nuget-source] [-o|--output]
[-u|--uninstall] [Template options]
dotnet new  [-l|--list] [--type]
dotnet new [-h|--help]

 

If we have any doubts in the arguments we can use flag –help to list the available arguments to that particular command. dotnet template engine will display the commands.

For example,

dotnet new --help

The above command lists the available templates in this version

args.png

Using the help of commands, we can create n number of application with the various application with different themes.

MVC web templates

For now, let’s explore whats new in MVC and angular web templates.

To explore MVC web templates, we can go ahead and create an MVC application using dotnet CLI from the and prompt with the owing command.


dotnet new mvc

Once the command executed, the CLI will create the required files for the MVC application and it will start to restore the dependencies as the post-creation actions.

mvc

The files have been generated with the following structure,

mvc-2.png

DotNet completed optimized this folder and file structure, and they have placed an only minimal code in the starter template. The main aim of this optimization is to provide a quick starter template for the user to get started with the project.

Even though we have a separate template to create an empty project, its always good to have a very minimal set of code with some working example in the project.

So the team has provided the very small set of code in this latest version templates if the user wants to override or delete the existing pages and getting started with the new project. That can be achieved with less number of deleting the existing code.

Let’s run the application and see how the new UI has been designed with command

dotnet run

 

mvc-3

The latest UI looks so clean, there are no such components – Jumbotron in the first half of page, 4 or 5 pages with user login feature. We are having only 2-page links here.

And as you see there is a default option to place the cookie accept policy details. Once the user clicks the Accept button, the message gets hidden and a flag is getting added in the browser cache. Until the user clears the browser for this particular web page, the message won’t show to the user again. That’s a helpful feature IMHO.

We 2 links called page 1, page 2 here, but those are not working in this preview release. In the standup call, the team provided the news that it will be fixed in the main release. And the team is looking for the feedback from the community to improve the templates.

I think we should add sidebar as an optional flag, we can let the user decide whether they need it or not. We don’t have to put it in the default templates page.

 

Angular web templates

Now, let’s explore the angular application web template.

We can follow the same approach

dotnet new angular
dotnet run

 

The angular web templates come up with following folder structure

spa.png

When we run the latest angular application template, we have got following UI pages,

angularangular1angular2

In the Home page, we have information about the single page application on what are all the UI framework and technology used in the application like –

In the counter page, we have a button and counter whenever we click the button the counter provides the number of clicks information.

In the Fetch date page, we have a table with bootstrap styles.

 

Bootstrap is fine here, but I wish the angular material design should get included as an optional flag. It will be great if have the material design support in the dotnet CLI itself.

That’s for now, thanks for reading.

Happy Coding!