Skip to content

Commit c603d05

Browse files
Merge pull request #104 from suprishi/devon4ng-mat-layout-review
Updated as per review comments
2 parents fb09d31 + 8c8e7ad commit c603d05

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

devon4ng-mat-layout/index.asciidoc

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,82 @@
11
= Create an Angular application with Angular Material components using devon4ng
22
====
3-
The purpose of this tutorial is to get a basic understanding of creating layouts using Angular Material in a devon4ng application. We will create an application with a header containing some menu links and a sidenav with some navigation links.
3+
The purpose of this tutorial is to get a basic understanding of creating layouts using Angular Material in a devon4ng application. You will create an application with a header containing some menu links and a sidenav with some navigation links.
44
55
## Prerequisites
6-
* devonfw-ide installed
76
* Basic Angular knowledge
87
98
## Learning goals
10-
In this tutorial we will learn how to:
9+
In this tutorial you will learn how to:
1110
* create an Angular application using the devon command
1211
* add Angular Material to the application
13-
* import Angular Material components into our modules
12+
* import Angular Material components into your modules
1413
* use Material icons in the application
1514
* use a prebulit theme to style the application
16-
* create layout (conataining a header with menu along with a sidenav with navigational links) with the Angular Material components
15+
* create layout (containing a header with menu along with a sidenav with navigational links) with the Angular Material components
1716
====
1817

1918
[step]
2019
--
21-
restoreDevonfwIde(["java","mvn", "npm", "ng"])
20+
restoreDevonfwIde(["npm", "ng", "vscode"])
2221
--
2322

2423
Before creating a devon4ng application, you first have to install the devonfw ide. You will find more information about devonfw on https://devonfw.com/website/pages/welcome/welcome.html.
25-
Once you have setup devonfw ide, you are ready to create your first devon4ng project.
24+
Once you have setup devonfw ide, you are ready to create your first devon4ng project.(Please wait until the devon setup completes and the command prompt becomes ready for writing commands in the integrated terminal here).
2625
[step]
2726
--
2827
createDevon4ngProject("devon4ng-mat-layout", "", ["--style=scss", "--routing=true", "--strict=false"])
2928
runClientNg("devon4ng-mat-layout", { "startupTime": 200, "port": 4200, "path": "" })
3029
--
3130

32-
Next we will add Angular Material to our application.
31+
Next you will add Angular Material to your application.
3332
[step]
33+
== Add Angular Material
3434
--
3535
npmInstall("devon4ng-mat-layout", {"name": "@angular/material @angular/cdk @angular/animations", "args": ["--save"]})
3636
--
3737

38-
Once the dependencies are installed, we need to import the BrowserAnimationsModule in our AppModule for animations support.
39-
Also, Angular Material provides a host of components for designing our application. All the components are well structured into NgModules. For each component from the Angular Material library that we want to use, we have to import the respective NgModule.
38+
Once the dependencies are installed, you need to import the BrowserAnimationsModule in your AppModule for animations support.
39+
Also, Angular Material provides a host of components for designing your application. All the components are well structured into NgModules. For each component from the Angular Material library that you want to use, you have to import the respective NgModule.
4040
[step]
41+
== Import Material components
4142
--
4243
changeFile("devon4ng-mat-layout/src/app/app.module.ts", { "file": "files/app.module.txt" })
4344
--
4445

45-
To use Material Design Icons along with the mat-icon component, we will load the Material Icons library in our `src/index.html` file.
46+
To use Material Design Icons along with the mat-icon component, you will load the Material Icons library in your `src/index.html` file.
4647
[step]
48+
== Load Material icons
4749
--
4850
changeFile("devon4ng-mat-layout/src/index.html", { "file": "files/index.txt" })
4951
--
5052

51-
Now that we have all the Angular Material related dependencies set up in our project, we can start coding. Let’s begin by adding a suitable `margin` and `font` to the body element of our single page application. We will add it in the `src/styles.scss` file to apply it globally.
53+
Now that you have all the Angular Material related dependencies set up in your project, you can start coding. Let’s begin by adding a suitable `margin` and `font` to the body element of your single page application. You will add it in the `src/styles.scss` file to apply it globally.
5254
[step]
55+
== Add global styles
5356
--
5457
changeFile("devon4ng-mat-layout/src/styles.scss", { "file": "files/styles.txt" })
5558
--
5659

5760
====
58-
We will clear the `app.component.html` file and setup a header with a menu button and some navigational links. We will use `mat-toolbar`, `mat-button`, `mat-menu`, `mat-icon` and `mat-icon-button` for this:
61+
Clear the `app.component.html` file and setup a header with a menu button and some navigational links. You will use `mat-toolbar`, `mat-button`, `mat-menu`, `mat-icon` and `mat-icon-button` for this:
5962
[step]
63+
== Add a header
6064
--
6165
changeFile("devon4ng-mat-layout/src/app/app.component.html", { "file": "files/app.component.txt" })
6266
--
63-
The color attribute on the mat-toolbar element will give it the primary (indigo) color as defined by our theme. The color attribute works with most Angular Material components; the possible values are `primary`, `accent` and `warn`. The `mat-toolbar` is a suitable component to represent a header. It serves as a placeholder for elements we want in our header. Inside the `mat-toolbar`, we start with a button having `mat-icon-button` attribute, which itself contains a `mat-icon` element having the value `menu`. This will serve as a menu button which we can use to toggle the `sidenav`. We follow it with some sample buttons having the `mat-button` attribute. Notice the first button has a property `matMenuTriggerFor` binded to a local reference submenu. As the property name suggests, the click of this button will display the mat-menu element with the specified local reference as a drop-down menu. The rest of the code is self explanatory.
67+
The color attribute on the mat-toolbar element will give it the primary (indigo) color as defined by your theme. The color attribute works with most Angular Material components; the possible values are `primary`, `accent` and `warn`. The `mat-toolbar` is a suitable component to represent a header. It serves as a placeholder for elements you want in your header. Inside the `mat-toolbar`, you start with a button having `mat-icon-button` attribute, which itself contains a `mat-icon` element having the value `menu`. This will serve as a menu button which you can use to toggle the `sidenav`. You follow it with some sample buttons having the `mat-button` attribute. Notice the first button has a property `matMenuTriggerFor` binded to a local reference submenu. As the property name suggests, the click of this button will display the mat-menu element with the specified local reference as a drop-down menu. The rest of the code is self explanatory.
6468
====
6569

66-
We want to keep the sidenav toggling menu button on the left and move the rest to the right to make it look better. To do this lets add the following style to the `menu` class in `app.component.scss`:
70+
You want to keep the sidenav toggling menu button on the left and move the rest to the right to make it look better. To do this add the following style to the `menu` class in `app.component.scss`:
6771
[step]
72+
== Shift header menu buttons to right
6873
--
6974
changeFile("devon4ng-mat-layout/src/app/app.component.scss", { "file": "files/app.component.scss.txt" })
7075
--
7176

72-
Next, we will create a sidenav. But before that lets create a couple of components to navigate between, the links of which we will add to the sidenav. You can use the `ng generate component` (or `ng g c` command for short) to create Home and Data components. But here, we will create them manually. We nest them in the `pages` sub-directory since they represent our pages. And we will also add the new components to our AppModule.
77+
Next, you will create a sidenav. But before that lets create a couple of components to navigate between, the links of which you will add to the sidenav. You can use the `ng generate component` (or `ng g c` command for short) to create Home and Data components. But here, you will create them manually. You nest them in the `pages` sub-directory since they represent your pages. And you will also add the new components to your AppModule.
7378
[step]
79+
== Create navigatable pages
7480
--
7581
createFile("devon4ng-mat-layout/src/app/pages/home/home.component.html", "files/home.component.txt")
7682
createFile("devon4ng-mat-layout/src/app/pages/home/home.component.scss", "files/home.component.scss.txt")
@@ -81,28 +87,35 @@ createFile("devon4ng-mat-layout/src/app/pages/data/data.component.ts", "files/da
8187
changeFile("devon4ng-mat-layout/src/app/app.module.ts", { "file": "files/app.module-components.txt" })
8288
--
8389

84-
Let us set up the routing such that when we visit the root url we see the `HomeComponent` and when we visit `/data` url we see the `DataComponent`. We had opted for routing while creating the application, so we have the routing module `app-routing.module.ts` setup for us. In this file, we have the empty routes array where we set up our routes:
90+
Let us set up the routing such that when you visit the root url you see the `HomeComponent` and when you visit `/data` url you see the `DataComponent`. You had opted for routing while creating the application, so you have the routing module `app-routing.module.ts` setup for us. In this file, you have the empty routes array where you set up your routes:
8591
[step]
92+
== Add routing
8693
--
8794
changeFile("devon4ng-mat-layout/src/app/app-routing.module.ts", { "file": "files/app-routing.module.txt" })
8895
--
8996

90-
We need to provide a hook where the components will be loaded when their respective URLs are loaded. We do that by using the `router-outlet` directive in the `app.component.html`:
97+
You need to provide a hook where the components will be loaded when their respective URLs are loaded. You do that by using the `router-outlet` directive in the `app.component.html`:
9198
[step]
9299
--
93100
changeFile("devon4ng-mat-layout/src/app/app.component.html", { "file": "files/app.component-routing.txt" })
94101
--
95102

96-
Let us finally create the sidenav. To implement the sidenav we need to use 3 Angular Material components: `mat-sidenav-container`, `mat-sidenav` and `mat-sidenav-content`. The `mat-sidenav-container`, as the name suggests, acts as a container for the `sidenav` and the associated content. So it is the parent element, and `mat-sidenav` and `mat-sidenav-content` are the children sibling elements. `mat-sidenav` represents the sidenav. We can put any content we want, though it is usually used to conatain a list of navigational links. The `mat-sidenav-content` element is for conataining our main page content. Since we need the `sidenav` application-wide, we will put it in the `app.component.html`
103+
Let us finally create the sidenav. To implement the sidenav you need to use 3 Angular Material components: `mat-sidenav-container`, `mat-sidenav` and `mat-sidenav-content`. The `mat-sidenav-container`, as the name suggests, acts as a container for the `sidenav` and the associated content. So it is the parent element, and `mat-sidenav` and `mat-sidenav-content` are the children sibling elements. `mat-sidenav` represents the sidenav. You can put any content you want, though it is usually used to conatain a list of navigational links. The `mat-sidenav-content` element is for conataining your main page content. Since you need the `sidenav` application-wide, you will put it in the `app.component.html`
97104
[step]
105+
== Create the sidenav
98106
--
99107
changeFile("devon4ng-mat-layout/src/app/app.component.html", { "file": "files/app.component-sidenav.txt" })
100108
changeFile("devon4ng-mat-layout/src/app/app.component.scss", { "file": "files/app.component-sidenav.scss.txt" })
101109
--
102110

103-
The sidenav’s width will be corrected when we add the navigational links to it. That is the only thing remaining to be done. Lets implement it now:
111+
The sidenav’s width will be corrected when you add the navigational links to it. That is the only thing remaining to be done. Lets implement it now:
104112
[step]
113+
== Style the sidenav
105114
--
106115
changeFile("devon4ng-mat-layout/src/app/app.component.html", { "file": "files/app.component-navlinks.txt" })
107116
changeFile("devon4ng-mat-layout/src/app/app.component.scss", { "file": "files/app.component-navlinks.scss.txt" })
108-
--
117+
--
118+
119+
====
120+
In this tutorial you learned how to create an angular application using devonfw-ide, add Angular Material to it and use its components to create a simple layout.
121+
====

0 commit comments

Comments
 (0)