Showing posts with label Angular-JS. Show all posts
Showing posts with label Angular-JS. Show all posts

Saturday, April 7, 2018

AngularJS 1.6 routing

Hi all,

Please find below a link to download and practice SPA in angular 1.6.


https://drive.google.com/open?id=1p0UEWVKMmmmixdGn3sEBGygJGYsidkEB

Please follow below steps to execute application
STEP 1: DOWNLOAD AND EXTRACT FROM PROJECT.
STEP 2: OPEN COMMAND AND EXECUTE FOLLOWING COMMANDS.

  1. npm install angula angular-route jquery
  2. npm install gulp -g
  3. npm install gulp gulp-rename gulp-concat gulp-uglify
STEP 3: DONWLOAD SERVER MEAN PROGRAM from below.

STEP 4: EXTRACT ABOVE PROJECT AND DO FOLLWING
  1. npm install
  2. npm start
STEP 5: IN CLIENT PROGRAM USE FOLLOWING COMMAND TO START SERVER
  1. npm install http-server -g
  2. http-server ./ -c-1
Thanks & regards,

Vikram Y.

Saturday, November 25, 2017

SPA Using angular-route.js & angular-ui-route.js

Hi All,

Please donwload below link to get the SPA examples. Use below command to donwload dependencies:

              npm install angular angular-router angular-ui-router

SPA Using angular-route.js & angular-ui-route.js

Thanks & regards,

Vikram Y.

Monday, November 20, 2017

EXPRESSIONS & FILTERS

EXPRESSION & FILTERS EXAMPLE
<html ng-app="myApp">
<body ng-controller="myCtrl">
<table border=1>
<caption>STUDENT DETAILS</caption>
<tr>
<td>FIRST NAME</td>
<td>{{student.fn | uppercase}}</td>
</tr>
<tr>
<td>LAST NAME</td>
<td>{{student.ln | lowercase}}</td>
</tr>
<tr>
<td>ROLL NO</td>
<td>{{student.rn}}</td>
</tr>
<tr>
<td>FULL NAME</td>
<td>{{student.fullName()}}</td>
</tr>
<tr>
<td>FEES</td>
<td>{{student.qty * student.price | currency: "&#8377;"}}</td>
</tr>
<tr>
<th colspan=2>STATE DETAILS</th>
</tr>
<tr>
<th colspan=2><input placeholder="Enter state filter text" ng-model="stateFilter"/></th>
</tr>
<tr>
<th>STATE CODE</th>
<th>STATE NAME</th>
</tr>
<tr ng-repeat="s in student.states | filter: stateFilter | orderBy:'-key' | limitTo: 5">
<td>{{s.key}}</td>
<td>{{s.name}}</td>
</tr>
</table>
<script src="node_modules/angular/angular.js"></script>
<script>
angular.module("myApp", [])
.controller("myCtrl", function($scope){
$scope.student = {
fn: "Naresh",
ln: "Student",
rn: 1001,
fullName: function(){
return this.fn + " " + this.ln;
},
qty: 16,
price: 172549.50,
states: [{"key":"AN","name":"Andaman and Nicobar Islands"},{"key":"AP","name":"Andhra Pradesh"},{"key":"AR","name":"Arunachal Pradesh"},{"key":"AS","name":"Assam"},{"key":"BR","name":"Bihar"},{"key":"CG","name":"Chandigarh"},{"key":"CH","name":"Chhattisgarh"},{"key":"DH","name":"Dadra and Nagar Haveli"},{"key":"DD","name":"Daman and Diu"},{"key":"DL","name":"Delhi"},{"key":"GA","name":"Goa"},{"key":"GJ","name":"Gujarat"},{"key":"HR","name":"Haryana"},{"key":"HP","name":"Himachal Pradesh"},{"key":"JK","name":"Jammu and Kashmir"},{"key":"JH","name":"Jharkhand"},{"key":"KA","name":"Karnataka"},{"key":"KL","name":"Kerala"},{"key":"LD","name":"Lakshadweep"},{"key":"MP","name":"Madhya Pradesh"},{"key":"MH","name":"Maharashtra"},{"key":"MN","name":"Manipur"},{"key":"ML","name":"Meghalaya"},{"key":"MZ","name":"Mizoram"},{"key":"NL","name":"Nagaland"},{"key":"OR","name":"Odisha"},{"key":"PY","name":"Puducherry"},{"key":"PB","name":"Punjab"},{"key":"RJ","name":"Rajasthan"},{"key":"SK","name":"Sikkim"},{"key":"TN","name":"Tamil Nadu"},{"key":"TS","name":"Telangana"},{"key":"TR","name":"Tripura"},{"key":"UK","name":"Uttar Pradesh"},{"key":"UP","name":"Uttarakhand"},{"key":"WB","name":"West Bengal"}]
};
});
</script>
</body>

</html>

CUSTOM FILTERS IN ANGULARJS
<html ng-app="myApp">
<body>
ENTER NUMBER: <input ng-model="no"/><br>
VIEW ORDINAL NO: {{no | ordinal}}
<script src="node_modules/angular/angular.js"></script>
<script>
function ordinal(no){
if(!no || isNaN(no))
return "";
if(parseInt(no)>10 && parseInt(no)<=20){
return no+"th";
}
var lastDigit = no % 10;
var ordinalNo = no;
if(lastDigit == 1){
ordinalNo += 'st';
}
else if(lastDigit == 2){
ordinalNo += 'nd';
}
else if(lastDigit == 3){
ordinalNo += 'rd';
}
else{
ordinalNo += 'th';
}
return ordinalNo;
};
angular.module("myApp", [])
.filter("ordinal", function(){
return ordinal;
});
</script>
</body>

</html>

Saturday, November 18, 2017

SHARING DATA BETWEEN CONTROLLERS USING $scope

1) Use $parent while binding premetive model object

<html ng-app="nestingApp">
<style>
div {
margin: 5px;
border: 1px solid gray;
padding: 10px;
}
</style>
<body>
<div ng-controller="ctrl1">
CTRL1 MSG: <input ng-model="msg"/>
<div ng-controller="ctrl2">
CTRL2 MSG: <input ng-model="$parent.msg"/>
<div ng-controller="ctrl3">
CTRL3 MSG: <input ng-model="$parent.$parent.msg"/>
</div>
</div>
</div>
<script src="node_modules/angular/angular.js"></script>
<script>
angular.module("nestingApp", [])
.controller("ctrl1", function($scope){
$scope.msg = "This is ctrl1 msg object.";
})
.controller("ctrl2", function($scope){})
.controller("ctrl3", function($scope){})
</script>
</body>

</html>

2) Use alias for controller bindings

<html ng-app="nestingApp">
<style>
div {
margin: 5px;
border: 1px solid gray;
padding: 10px;
}
</style>
<body>
<div ng-controller="ctrl1 as c1">
CTRL1 MSG: <input ng-model="c1.msg"/>
<div ng-controller="ctrl2 as c2">
CTRL2 MSG: <input ng-model="c1.msg"/>
<div ng-controller="ctrl3">
CTRL3 MSG: <input ng-model="c1.msg"/>
</div>
</div>
</div>
<script src="node_modules/angular/angular.js"></script>
<script>
angular.module("nestingApp", [])
.controller("ctrl1", function(){
this.msg = "This is ctrl1 msg object.";
})
.controller("ctrl2", function($scope){
$scope.c1.msg = "Updated in ctrl2";
})
.controller("ctrl3", function($scope){})
</script>
</body>

</html>

3) Use json denfinition while defining models

<html ng-app="nestingApp">
<style>
div {
margin: 5px;
border: 1px solid gray;
padding: 10px;
}
</style>
<body>
<div ng-controller="ctrl1">
CTRL1 MSG: <input ng-model="user.msg"/>
<div ng-controller="ctrl2">
CTRL2 MSG: <input ng-model="user.msg"/>
<div ng-controller="ctrl3">
CTRL3 MSG: <input ng-model="user.msg"/>
</div>
</div>
</div>
<script src="node_modules/angular/angular.js"></script>
<script>
angular.module("nestingApp", [])
.controller("ctrl1", function($scope){
$scope.user = {
msg: "This is ctrl1 msg object."
};
})
.controller("ctrl2", function($scope){
})
.controller("ctrl3", function($scope){})
</script>
</body>

</html>

4) $scope METHODS

<html ng-app="nestingApp">
<style>
div {
margin: 5px;
border: 1px solid gray;
padding: 10px;
}
</style>
<body>
<div ng-controller="ctrl1">
CTRL1 MSG: <input ng-model="msg" ng-keyup="updateModel(msg)"/>
<div ng-controller="ctrl2">
CTRL2 MSG: <input ng-model="msg" ng-keyup="updateModel(msg)"/>
<div ng-controller="ctrl3">
CTRL3 MSG: <input ng-model="msg" ng-keyup="updateModel(msg)"/>
</div>
</div>
</div>
<script src="node_modules/angular/angular.js"></script>
<script>
angular.module("nestingApp", [])
.controller("ctrl1", function($scope){
$scope.msg = "This is ctrl1 msg object.";
$scope.updateModel = function(msg){
$scope.$broadcast("toChild", msg);
};
$scope.$on("toParent", function(event, data){
$scope.msg = data;
});
})
.controller("ctrl2", function($scope){
$scope.updateModel = function(msg){
$scope.$broadcast("toChild", msg);
$scope.$emit("toParent", msg);
};
$scope.$on("toParent", function(event, data){
$scope.msg = data;
});
$scope.$on("toChild", function(event, data){
$scope.msg = data;
});
})
.controller("ctrl3", function($scope){
$scope.updateModel = function(msg){
$scope.$emit("toParent", msg);
};
$scope.$on("toChild", function(event, data){
$scope.msg = data;
});
});
</script>
</body>

</html>

Monday, August 28, 2017

Angular BEST PRACTICES example

BEST PRACTICES

Please find the link below to download a simple project.

https://drive.google.com/open?id=0B9AYB6a-0LPnOEZ0Qm1TRUhucnc

Please follow below steps to execute project
extract rar files into any folder
open command and install node & npm
in command cd to rar extacted folder and execute below commands

npm install angular
npm install -g gulp
npm install gulp gulp-contact gulp-uglify gulp-rename
gulp build


After performing above commands open best-practice.htm file any browser.

Thanks & regards,

Vikram Y.

Saturday, August 12, 2017

Friday, November 4, 2016

AJAX Example(javascript, jquery, angularjs)

Hi All,

Please use below link to download ajax example using nodejs and mysql as backend.

MEAN & AJAX EXAMPLE

MYSQL student DATABASE SCHEMA

JQUERY AJAX EXAMPLE(CONTAINS GET & POST EXAMPLE)

START SERVER TO UP AND RUNNING SERVER SIDE PROGRAMS
1) open command route to mean use npm install.
2) open mysql workbench import database schema.
3) then in command use npm start to start serever.

START SERVER TO UP AND RUNNING CLIENT SIDE PROGRAMS
1) Extract ajax.rar file and open location in command.
2) Use below command to run client programs using server:
                  npm install http-server -g
3) Use below command to run client side programs:
                  http-server ./ -c-1

Thanks & regards,

Vikram Y.

Friday, May 13, 2016

Angular-JS latest post with classroom programs and examples...

Hi All,

Everybody is saying that some of classroom programs are missing in my previous post. So please find the updated post which contains all programs including MEAN example.

All classroom programs

Thanks & regards,

Vikram Y.

Tuesday, June 30, 2015

Wednesday, June 17, 2015

please find topicwise notes

Dear All,

Please find the below notes topicwise:

ANIMATIONS

AngularJS 1.3 provides animation hooks for common directives such as ngRepeat, ngSwitch, and ngView, as well as custom directives via the $animate service. These animation hooks are set in place to trigger animations during the life cycle of various directives and when triggered, will attempt to perform a CSS Transition, CSS Keyframe Animation or a JavaScript callback Animation (depending on if an animation is placed on the given directive). Animations can be placed using vanilla CSS by following the naming conventions set in place by AngularJS or with JavaScript code when it's defined as a factory.

Animations are not available unless you include the ngAnimate module as a dependency within your application.

How they work

Animations in AngularJS are completely based on CSS classes. As long as you have a CSS class attached to a HTML element within your website, you can apply animations to it.

Which directives support animations?

A handful of common AngularJS directives support and trigger animation hooks whenever any major event occurs during its life cycle. The table below explains in detail which animation events are triggered


DirectiveSupported Animations
ngRepeatenter, leave, and move
ngViewenter and leave
ngIncludeenter and leave
ngSwitchenter and leave
ngIfenter and leave
ngClassadd and remove
ngShow & ngHideadd and remove
(the ng-hide class value)

DIRECTIVES

What are Directives?

At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element or even transform the DOM element and its children.

For AngularJS, "compilation" means attaching event listeners to the HTML to make it interactive.

Directive types
---------------
$compile can match directives based on element names, attributes, class names, as well as comments.

All of the Angular-provided directives match attribute name, tag name, comments, or class name. We can define a directive as attribute/tag name/class name like fallows:

<my-dir></my-dir>
<span my-dir="exp"></span>
<!-- directive: my-dir exp -->
<span class="my-dir: exp;"></span>

NOTE: Prefer using directives via tag name and attributes over comment and class names. Doing so generally makes it easier to determine what directives a given element matches.



Creating Directives
-------------------
Much like controllers, directives are registered on modules. To register a directive, WE use the module.directive API.

module.directive takes the normalized directive name followed by a factory function. This factory function should return an object with the different options to tell $compile how the directive should behave when matched.

The factory function is invoked only once when the compiler matches the directive for the first time. You can perform any initialization work here. The function is invoked using $injector.invoke which makes it injectable just like a controller.

PROPERTIES
----------
Restrict
--------
This simply restricts the way WE can define a directive. As we can restrict it as:

E: elements
A: attributes
C: class names (CSS)
M: comments

Template
--------
This basically replaces the existing contents of an element.

TemplateUrl
-----------
If we keep adding more and more details to above card, maintaining the template markups within the directive’s definition will become complicated and unmanageable. So, its better to keep our template in a separate html file and reference its location in templateUrl. As the template loading is asynchronous in this case, so the compilation/linking will be delayed until the template is fully loaded, and will be cached in $templateCache for later use.

priority
--------
This option tells angular to sort directives by priority so a directive having higher priority will be compiled/linked before others.

Transclude
----------
This option tells angular to get ready for transclusion by providing transclude linking function available in a compile function of a directive.

Scope
-------
Setting scope will only create/maintain the hierarchy between the scope of an element and its parent scope but you can still access data bound to parents’ scopes.

scope: false (DEFAULT)

scope: true   (Creates a new scope but prototypically inherits from the parent scope)

scope: isolate (Creates an isolated scope which does not prototypically inherit from the parent scope but you can access parent scope using scope.$parent)

Require
-------
This lets US pass a controller associated with another directive into a compile/linking function. You have to specify the name of the directive to be required – It should be bound to same element or its parent.

Controller
----------
This can be treated as a control room for a directive. You can either bind properties/methods to available $scope or this keyword. The data bound to this will be accessible in other directives by injecting the controller using require option.

Compile
-------
A compile function produces a link function. This is the place where we can do the DOM manipulation mostly. This takes 2 arguments by default:
tElement – A template element the directive has been declared on.
tAttrs – A list of attributes associated with the tElement.

Link
----
Its job is to bind a scope with a DOM resulted in a 2-way data binding. We have access to scope here unlike compile function so that we can create custom listeners using $watch method. As expected it takes 3 arguments:

scope – A scope to be used by the directive.
element – An element the directive is bound to.
attrs – A list of attributes associated with the element.

CUSTOM SERVICE'S

AngularJS supports the concept of Separation of Concerns using services architecture. Services are JavaScript functions, which are responsible to perform only specific tasks. This makes them individual entities which are maintainable and testable. The controllers and filters can call them on requirement basis. Services are normally injected using dependency injection mechanism of AngularJS.

AngularJS provides many inbuilt services. For example, $http, $route etc. Each service is responsible for a specific task such as the $http is used to make ajax call to get the server data, the $route is used to define the routing information, and so on. The inbuilt services are always prefixed with $ symbol.

Angular provides us with three ways to create and register our own service.
1) Factory
2) Service
3) Provider

Using Factory Method

When we’re using a Factory we create an object, add properties to it, then return that same object. When you pass this service into your controller, those properties on the object will now be available in that controller through your factory.

var myApp = angular.module("myApp", []);

myApp.factory('MathFactory', function() {
return{
multiply: function(a, b) {
return a * b
}
};
});

Using Service Method

When you’re using Service, it’s instantiated with the ‘new’ keyword. Because of that, you’ll add properties to ‘this’ and the service will return ‘this’. When you pass the service into your controller, those properties on ‘this’ will now be available on that controller through your service.

myApp.service('CalcService', function(){
this.calc = function(a, b) {
return a * b;
}
});

USING PROVIDER METHOD

Providers are the only service you can pass into your .config() function. Use a provider when you want to provide module-wide configuration for your service object before making it available.

myApp.provider('SqareProvider', function() {
    this.a = 0;
    this.$get = function() {
        var a = this.a;
        return {
            sqare: function() {
                return a * a;
            }
        }
    };
    this.setValue = function(a) {
        this.a = a;
    };
});

What to choose?

As usual, it depends. The factory has the Revealing Module pattern which gives the possibility to hide private variables. This can be very useful. However if you don’t have them and the injection of the service isn’t a problem for you, the service can be useful for you as well. The provider is the last in line to use. In most cases you won’t use this one. Use this only when you need the config part. This can be very handy when developing services that were shared of applications.

ANGULAR JS UNIT TESTING

JavaScript is a dynamically typed language which comes with great power of expression, but it also comes with almost no help from the compiler. For this reason ANGULAR feel's very strongly that any code written in JavaScript needs to come with a strong set of tests. Angular have built many features which makes testing your Angular applications easy. So there is no excuse for not testing.

Unit testing, as the name implies, is about testing individual units of code. Unit tests try to answer questions such as "Did I think about the logic correctly?" or "Does the sort function order the list in the right order?"

In order to answer such a question it is very important that we can isolate the unit of code under test. That is because when we are testing the sort function we don't want to be forced into creating related pieces such as the DOM elements, or making any XHR calls to fetch the data to sort.

For testing Angular applications there are certain tools that you should use that will make testing much easier to set up and run.

Karma

Karma is a JavaScript command line tool that can be used to spawn a web server which loads your application's source code and executes your tests.

Jasmine

Jasmine is a behavior driven development framework for JavaScript that has become the most popular choice for testing Angular applications. Jasmine provides functions to help with structuring your tests and also making assertions. As your tests grow, keeping them well structured and documented is vital, and Jasmine helps achieve this.

In Jasmine we use the describe function to group our tests together:

describe("sorting the list of users", function() {
// individual tests go here
});

And then each individual test is defined within a call to the it function:

it('sorts in descending order by default', function() {
// your test assertion goes here
});

angular-mocks

Angular also provides the ngMock module, which provides mocking for your tests. This is used to inject and mock Angular services within unit tests. In addition, it is able to extend other modules so they are synchronous. Having tests synchronous keeps them much cleaner and easier to work with. One of the most useful parts of ngMock is $httpBackend, which lets us mock XHR requests in tests, and return sample data instead. Please fallow below link to check installation procedure of karma test runner.

$resource example with java rest api communication

Hi All,

Please find below program.

Angular-JS $resource example Rest API eclipse project

Thursday, May 21, 2015

Angular-JS ngRoute example

Dear All,

Please fallow below link to get SPA using ngRoute source code.

SOURCE CODE

Thanks & regards,

Vikram Y.

Angular-JS transformReponse Using $http service

Dear All,

Please fallow the link below to download source code.

SOURCE CODE

Thanks & regards,

Vikram Y.

Friday, May 8, 2015

ANGULAR JS REF. SOFTCOPY

Dear All,

Please find the below link to get angular js quick ref. softcopy.

PDF LINK

Thanks & regards,

Vikram Y.

UNIT TESTING EXAMPLE

Dear All,

Please find the below link for unit testing example.

SOURCE CODE

Thanks & regards,

Vikram Y.

ui-router example

Dear All,

Please find the below link for ui-router example.

SOURCE CODE

Thanks & regards,

Vikram Y.

Wednesday, March 25, 2015

SPA Project

Dear All,

Please find the below link to get database, ajax & service integration in angular-js.

SOURCE CODE

Download the application and extract it. Please fallow the read me file to execute application.

Wednesday, March 18, 2015

Angular-JS integration with Visual Studio

integrating with vs
-------------------
You can search for the template from with Visual Studio by navigating to Tools->Extension and Updates

https://visualstudiogallery.msdn.microsoft.com/cc6c9c5f-2846-4822-899f-a6c295cd4f2b

Once you install the template on your machine, you would get a new option for ASP.Net MVC 4 project type when you create a new project in Visual Studio.

Select the new AngularjS SPA template and create a new project. Once the project is created, add the prerequisite nuget package  and compile and run the project.

Note: When you create a new project using the SPA template, you need to install all the prerequisite nuget packages manually using either Nuget Package Restore option available on the Visual Studio solution or using Nuget.exe on command line
nuget install packages.config

If you are having problems with package restore, make sure you are using the latest nuget package manager in Visual Studio.

fallow below link for integration angularjs in vs 2015

http://stephenwalther.com/archive/2015/01/12/asp-net-5-and-angularjs-part-1-configuring-grunt-uglify-and-angularjs

Thursday, March 12, 2015

ng-view and routeProvider

Dear All,

Please find the source related to ng-view and routeProvider. Please fallow readme.txt file to execute the application.

SOURCE CODE LINK

Thanks & regards,

Vikram Y.

Wednesday, March 11, 2015

Ajax request

Please find the fallowing attachment. Fallow the read me file to execute programs.


HTTP-METHOD SOURCE CODE USING JSONP

If you find any issues please put a comment.

Thanks & regards,

Vikram Y.