Posts

Showing posts from 2018

More Features on Angular

Image
As I promised in my previous post, today I am going to talk about how to declare scope variable and bind the variables to the view. Here we are going to use the $scope object to communicate with our view. The $scope variable allows us to tell our HTML that there is a value in our controller that needs to be displayed in the HTML. Here also I take the example that I talked about in my previous post. So, let's see how to do it.  Open menuController.js file and inside the main function ($scope) method, to create a property named "title" enter the following code.                                          $scope.model = {title: 'Our Menu'}; In index.html file  Inside the <h2> tag, to display the title variable that you just defined inside your controller rather than static text, replace the contents of the  <h2>  tag with  {{model.title}} . It is best practice to always bind to an object off of the scope, in this case, "model". T

Using Controllers in AngularJS

Image
The controllers primary purpose is to control the view model contained within the Angular scope. Controllers are used in AngularJS to: Set the initial state of Scope variables, which are then made available for the View to consume and interact with Add behavior to the Scope by two-way binding variables and declaring Scope functions Set up communications to and from the view and Model objects such as Services, brought in through Dependency Injection Angular invokes the controller with a $scope object. Any objects (or primitives) assigned to the scope become model properties. The role of controllers in Angular is to expose data to our view via $scope, and to add functions to $scope that contain business logic that enhances view behavior.  A controller should contain only the business logic needed for a single view; presentation logic should remain within views and directives. Controllers are created by registering with an existing Angular Module. var app = angular

Getting Started with Angular

Image
In the phase of beginning of my post, I’d like to give a brief introduction about Angular. Angular is an open source web framework for JavaScript applications. Nowadays Angular has become an outstanding web development framework because of the following reasons.   Provides improved application design architecture Promotes code  re usability Consists of easy to remove components Employs two way data binding Angular contains the following core types of objects and components. Modules Controllers Services   Directives These core components can be injected into each other using Dependency Injection (DI) mechanism built in Angular. DI is a software design pattern that assigns dependencies to components instead of hard coding them within the component itself. Angular uses a feature called directives that allow to write HTML code, which then builds the HTML of the application instead of using templates to generate the user interface. The adoption of two-way data bindi