Monday, March 27, 2017

Angular JS 2

Need Node.js, NPM and Git


Module
  • The module component is a block of code which can be used to perform a single task
  • You can export the value of something from the code such as a class
  • The Angular apps are called as modules and build your application using many modules. 
  • The basic building block of Angular 2 is a component class which can be exported from a module.
Component 
  • is a controller class with a template which deals with a view and logic on the page. 
  • Component knows how to render itself and configure dependency injection
  • You can associate CSS styles using component inline styles, style urls and template inline styles to a component.
  • To register component, we use @Component annotation and can be used to break up the application into smaller parts. There will be only one component per DOM element.
Template
  • The component's view can be defined by using the template which tells Angular how to display the component.
  • To display the value, you can put template expression {{name}} within the interpolation braces.
Metadata
  • Metadata is a way of processing the class
  • E.g. we have one component called MyComponent which will be a class until we tell Angular that it's a component. You can use metadata to the class to tell Angular that MyComponent is a component. 
  • The metadata can be attached to TypeScript by using the decorator.
Data Binding
  • Data binding is a process of coordinating application data values by declaring bindings between sources and target HTML elements
  • It combines the template parts with components parts and template HTML is bound with markup to connect both sides. 
  • There are four types of data binding:
    • Interpolation: It displays the component value within the div tags.
    • Property Binding: It passes the property from the parent to property of the child.
    • Event Binding: It fires when you click on the components method name.
    • Two-way Binding: This form binds property and event by using the ngModel directive in a single notation.
Service
  • Services are used for reusable data services to access data (Get Data From API / Databases) to from or share by all components.
  • Angular services are injected using Dependency Injection mechanism. (asynchronous
  • So Component only focus for supporting the view.
  • Service includes the value, function or feature which is required by the application. Generally, service is a class which can perform something specific such as logging service, data service, message service, the configuration of application etc. There is nothing much about service in Angular and there is no ServiceBase class, but still services can be treated as fundamental to Angular application.
Directive
  • The directive is a class that represents the metadata. There are three types of directives:
    • Component Directive: It creates custom controller by using view and controller and used as custom HTML element.
    • Decorator Directive: It decorates the elements using additional behavior.
    • Template Directive: It converts HTML into a reusable template.
Dependency Injection
  • Dependency Injection is a design pattern that passes an object as dependencies in different components across the application. It creates new a instance of class along with its required dependencies.
You must remember the below points while using Dependency Injection:
  • The Dependency Injection is stimulated into the framework and can be used everywhere.
  • The injector mechanism maintains service instance and can be created using a provider.
  • The provider is a way of creating a service.
  • You can register the providers along with injectors.

Monday, March 6, 2017

Node.js


  • built on Google Chrome's Javascript Engine. (Written in Javascript)
  • Single thread application but run in concurrency support by callbacks and event.
  • Runtime environment + Javascript Library = Node.js
  • Open Source.
  • Cross platform ( run on OS X, Windows, and Linux)

Features
  • Acronymous and Event Driven 
    • All API's of Node.js Library is Acronymous with non-blocking. (Never wait for API return data)
    • E.g. Server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.
  • Very Fast
  • Single Threaded but Highly Scalable 
    • Use a single threaded model with event looping.
    • Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as  not like traditional servers (create limited threads to handle requests)
    • Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.

Blocking Code

  • The program blocks until it reads the file and then only it proceeds to end the program.

  • Read From File!!!!!
    Program Ended
Non-Blocking Code
  • The program does not wait for file reading and proceeds to print "Program Ended" and at the same time, the program without blocking continues reading the file.

  • Program Ended
    Read From File!!!!

Callback 
  • is an asynchronous equivalent for a function. 
  • is called at the completion of a given task. 
  • Node.js heavy use of callbacks. All the APIs of Node.js are written in such a way that they support callbacks.
  • E.g. a function to read a file may start reading the file and return the control to the execution environment immediately so that the next instruction can be executed. Once file I/O is complete, it will call the callback function while passing the callback function, the content of the file as a parameter. So there is no blocking or wait for File I/O. This makes Node.js highly scalable, as it can process a high number of requests without waiting for any function to return results.
Event-Driven Programming
  • Node.js starts its server, it simply initiates its variables, declares functions and then simply waits for the event to occur.
  • In an event-driven application, there is a main loop that listens for events and then triggers a callback function when one of those events is detected.
  • Node.js uses observer pattern. Node thread keeps an event loop and whenever a task gets completed, it fires the corresponding event which signals the event listener function to execute.
  • Whenever an event gets fired, its listener function starts executing. 
  • Node.js has multiple in-built events (events module and EventEmitter) which used to bind events and event-listeners.
Different Event and Callback
  • Callback functions are called when an asynchronous function return its result.
  • Whereas event handling work on observer pattern.

Thursday, March 2, 2017

Different Between Javascript and AngularJS expression

Angular JS

  • is a Javascript Framework
  • ng-app 
      • root element of Application (Tell HTML to use AngularJS)
  • ng-controller
      • Define Controler.
  • ng-model
      • Bind HTML Control value to App Data.
  • ng-bind
      • Bind App Data to HTML Control Value.
      • {{expression}} = output {{5+5}} = 10 
  • ng-int 
      • Initialize AngularJS app variable (JSON)
  • Service(AJAX) : $http
      •  Read Data from Server side(HTTP Request) / Text File
  •  $scope : parameter passed to the controller
      • Is Model Between Controller and Views
      • $scope.message & $scope.type is to display in HTML page.
  • Validate Data
      • $dirty : value has changed ?
      • $Invalid: value is Invalid ?
      • $error: State exact error.
  • Include
      • Embedding HTML Page
      • Can more than 1 in 1 HTML Page.
      •  For Code Reuse
      • Good For Header/ Footer/ Sidebar
  • ng-view
      • Partial Represent with controller and Route (Page's URL)
      • Only 1 per HTML Page.
      • Good For Content of the page.
      • and Change by URL (Category, PageNum, ID)
  • ng-template
      • Create an html view using Script Tag.
      • It contrain "id", and use &routeProvider to map a view with controller.
  • &routeProvider
      • Key configuration of URL map with HTML or ng-template