Skip to main content

Learn Angular 4 from scratch

Angular 4 is the latest version of AngularJs released in March 2017.


The basic steps to accomplish our first Angular 4 hello world example.

Here, we’ll simply create a component that passes the title from component to the view.

1. Install Angular CLI
The Angular CLI is a command line interface that helps to scaffold and build angular apps in Node.js style.

Also, it set up the angular 4 environments and will be helpful for us to work with angular apps like creating, running, etc.

Now, install Angular-CLI.

<code>npm install -g angular-cli</code>

Once installation is done, just make sure that it’s installed by checking it’s version.

<code>ng -v</code>

2. Install an Angular 4 Hello World App
Here, we will create an app named hello-world

ng new hello-world
Now, go to the directory of a newly created project.

cd hello-world
Before running your app, let’s dive a bit deeper in coding behind the picture.

2.1 Firstly, let’s see what’s AppModule is?
App Module Filepath: app/app.module.ts

<code>//Import angular core
import { NgModule } from '@angular/core';
//Import Browser module
import { BrowserModule } from '@angular/platform-browser';
//Import App Component
import { AppComponent } from './app.component';
//Declarations
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
//Bootstrap
export class AppModule {}</code>

After the import statements, you can see the class with the @NgModule decorator.

The @NgModule decorator will identify the main module (i.e AppModule) as an Angular module class or a NgModule class. @NgModule tells Angular about the compilation and launch of an application.

Basically, three things you should know at this point.

imports — the BrowserModule that this and every application needs to run in a browser.
declarations — the application’s lone component, which is also …
bootstrap — is the root component that Angular creates and inserts into the index.html.
The Angular Modules (NgModule) will take you deep into the details of Angular modules. All you need to know at the moment is a few basics about these three properties.

2.2 Secondly, let’s see what App Component has
The app component has defined the title and this title will be rendered by template.

App Component Filepath: app/app.component.ts

<code>//Imports
import { Component } from '@angular/core';
//Decorator
@Component({
selector: 'hello-world',
templateUrl: 'src/app/app.component.html'
})
//Class
export class AppComponent {
constructor() {}
title: string = 'A Hello World App In Angular 4';
}</code>

2.3 Finally, let’s see HTML of an App Component
Here, the title will be rendered with the value which is set for title variable in-app component.

Template Filepath: app/app.component.html

<code><div>
<h2>{{title}}</h2>
</div></code>

3. All set to run the App
Finally, let’s run.

<code>ng serve</code>

That’s it, open your browser on http://localhost:4200 which will say A Hello World App In Angular 4


Comments

Popular posts from this blog

Why Prestashop is the best eCommerce platform?

Why Prestashop is the best eCommerce  platform? E-commerce is the current buzzword in the online world. Every business owner desires to have online eCommerce website to reach many people and get more sales. Prestashop is the one of the best eCommerce solution for the best eCommerce site because of its feature. Free, Open-source Prestashop is totally free to download, You don't need to pay for using it. Supports whenever you need them. Best part of this is you don't need to search for the required documentation as these are available on the website of Prestashop. Easy to Install  And Smart Back-End Prestashop scores very high in the segment of usability. The installation is very easy and the installation requires very little technical skills. PrestaShop helps you to run your store in a manner that proves beneficial for you. It is highly impressive and it is even integrated with all the major carriers such as UPS, FedEx and USPS. Also, the backend dashboard o...

Latest PHP web development trends

1) Faster and leaner PHP 7 - PHP 7 looks familiar for developers, but it is especially focused on high performance. - Experts predict the growth of PHP 7 adoption rate, and they have several reasons for verifying such forecast.  - Using PHP 7 the performance of applications has gained up twice comparing with older versions.  - RAM consumption was decreased by 50% during the request processing in PHP 7. - Previously there are many errors which are reason of application stop working now those can be processed as exceptions - The most popular CMS and frameworks such as WordPress, Magento and Symfony ready for PHP 7. - All these changes of PHP 7 increase application speed and reduce resources needs. 2) Market forecast - Experts predict that by 2025 half of American enterprises are expected to run more than 10 applications. - Though PHP cannot be the best choice for any web solutions, it is still holding the lead positions in the development of tech startups...

Sass

Sass: Here we are now introducing some other facts about the Sass Css Framework. Sass is the latest framework of css that is trending now very fast and it's professional, mature and powerful grade css version comparing to old versions. The Sass css is adapted by bootstrap also and other framework also so it is going fastly worldwide and many more industries are not moving to Sass. Basically Sass is the precompiled css version. It is help to load the page fastly then older css versions. Sass can be compiling through Gulp Js, Grunt and other compiler software also. It is latest version but still it is compatible with the all old versions of the css frameworks. It is working with the dynamic variables like for colors, spacing and different sections containers etc. Like, in this css framework the value of color is described once in variable but the variable can be used multiple time and in many files so if we want to change the color so we just have to change at one place...