Thursday, June 11, 2015

Angular js Question

The basic steps & use of AngularJS?
Filter in Angular MVC5
For-each in AngularJS MVC5
Increment counter in AngularJS
AngularJS index counter in ng-repeat
Add rows in AngularJS
How to delete a row in AngularJS
How to use AngularJS data grid ng-grid


angularjs date format
angularjs date calendar example
how to upload file in angularjs
drop down list in angularjs
configuring routes in angularjs
using angularjs $watch example
Angularjs ng-repeat using JSON object
angularjs i18n and L10n language translation
ng-if else in angularjs
ng-show and ng-hide in angularjs
angularjs date calendar example
css binding in angularjs
email validation in angularjs
ng-pattern validation in angularjs
angularjs form validation
angularjs phone number validation
angularjs url validation
angularjs required validation using ng-pattern
How to handle check-box and radio button in Angularjs example ?
$scope vs scope in angularjs
set default value in option/drop-down list in angularjs
How to add dynamically input fields to form using AngularJS?
How to develop Star Rating demo application in angularjs?
How to use ng-href directives in angularjs?
What about $new() or $rootScope.new() in angularjs?
Difference between $watch vs $on in angularjs?
What about $http.get $http.post and $http.put in angularjs?
Export ng-grid data to Excel, CSV and PDF format in angularjs
custom row template in ng-grid angularjs
ng-grid edit delete row in angularjs
AngularJS ng-grid filter - filterText format
How to create and What is the use of module in angularjs?
filter nested properties in angularjs object
countdown watch timer in angularjs
Login HTTP Authentication in AngularJs
Confirmation dialog box in AngularJs
AngularJs add edit delete functionality
AngularJs submit form data to server using API 2
Confirm Password Validation in AngularJs
How to show ui ng-grid show spinner loader in AngularJs
How to Access MVC 5 Web API 2 in AngularJs
How to format a date-time column in ng-grid
AngularJs ng-grid multiple fields in a single cell column
How to set ng-grid row or cell height in AngularJs
How to display confirm dialog if check-box is checked or unchecked in angularjs with ng-click event?
How to auto capitalize input characters in angularjs text-box?
Text filtering while using selection box in angularjs?
How to use Multiple ng-app within one page in AngularJs?
How to enabling CORS in angularjs?
How to paging in ng-grid angularjs?
Angularjs file bulk upload using MVC 5
spark-line chart using angularjs directive
What about ng-Cloak directive in AngularJs?
What are Directives in AngularJs?
What is $scope in Angularjs?
Auto bootstrap process in AngularJs
AngularJs initialize options on page load
How to show/hide buttons in AngularJs?
AngularJs looping over collection items
How to bind selection box with options in AngularJs?
What are filters in AngularJs?
What is the difference between ng-app vs. data-ng-app and x-ng-app?
What are scope and scope inheritance?
Top 10 Security Risks for AngularJs Developers
bind image control in angularjs
How to hide column in AngularJs ng grid?
Auto Refresh div using $interval() AngularJs?
The Types of $http Service in AngularJs.
Dynamically add directives in AngularJs
how to pass an argument to AngularJs Custom Filter?
What's new in angularjs 2.0? What Are the Changes? Why Angular 2.0?
The $http synchronous call in angularjs?
Radio button list in ng-repeat AngularJs
Angularjs check-box checked and unchecked
How to use ng-readonly and ng-disabled in angularjs?
Constants in AngularJs
How to inject to services, factories and providers?
What are constant and value in angularjs?
How to ng-repeat through returned items by calling a function on ng-init?
How to use ng-style in AngularJs?
How to set authorization header on $http request in angularjs with MVC5?
How to inject services into AngularJs controllers?
What is services? How to create services in angularjs? how to use it?
ng-repeat in angularjs
AngularJs toggle using ngShow ngHide and ngClick
Password Strength Validation using Regular Expression in AngularJs
How to get selected drop-down value in angularjs?

How to set authorization header on $http request in angularjs with MVC5?

How to set HTTP header for $http.GET request in angularjs?

The AngularJs code sample as given below

//This is the global
var baseURL = "http://localhost:8080/";
var emailId = window.utility.user.EmailID
var userID = window.utility.user.UserID;
var userLocationID = window.utility.user.UserLocationID;

var authInfo = {
    Authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
    UserID: userID,
    UserLocationID: userLocationID
};
//END

var app = angular.module('authApp', []);

//This is the angular services
app.service("myAuthServices", function ($http) {
    this.getUsers = function (url) {
        return $http({
            method: 'GET',
            url: baseURL + url,
            headers: authInfo
        });
    };
});

//This is the angular controller.
app.controller('baseController', function ($scope, myAuthServices) {

    //This is default values.
    $scope.users = null;
    var apiURL = "api/Users_API/GetUsers/";

    //Call get user services.
    myAuthServices.getUsers(apiURL).then(function (resp) {
        if (resp !== undefined && resp !== null) {
            if (resp.data !== undefined && resp.data !== null) {
                $scope.users = resp.data;
            }
        }
    });
});

MVC5 part code sample as given below

[RoutePrefix("api/Users_API")]
public class Users_APIController : ApiController
{
    UsersRepository _repoUser = new UsersRepository();

    [Route("GetUsers")]
    public IHttpActionResult GetUsers()
    {
        long UserID = 0, UserLocationID = 0; string EmailID = null;

        if (Request.Headers.Contains("Authorization"))
            EmailID = Request.Headers.GetValues("Authorization").First();
        if (Request.Headers.Contains("UserID"))
            UserID = Convert.ToInt32(Request.Headers.GetValues("UserID").First());
        if (Request.Headers.Contains("UserLocationID"))
            UserLocationID = Convert.ToInt32(Request.Headers.GetValues("UserLocationID").First());

        var result = _repoUser.GetCompUsers(EmailID, UserID, UserLocationID);
        return Json(result);
    }
}

inheritance in JavaScript

inheritance in JavaScript


In the JavaScript, we can implement the inheritance using the some alternative ways and we cannot define a class keyword but we create a constructor function and using new keyword achieve it.  

The some alternative ways as given  below.
  1. Pseudo classical inheritance
  2. Prototype inheritance
Pseudo classical inheritance is the most popular way. In this way, create a constructor function using the new operator and add the members function with the help for constructor function prototype.

The prototype based programming is a technique of object oriented programming. In this mechanism we can reuse the exiting objects as prototypes. The prototype inheritance also know as prototypal, 
classless or instance based inheritances.

The Inheritance example for prototype based as given below

  // Create a helper function.
    if (typeof Object.create !== 'function') {

        Object.create = function (obj) {
            function fun() { };
            fun.prototype = obj;
            return new fun();
        };
    }

    //This is a parent class.
    var parent = {
        sayHi: function () {
            alert('Hi, I am parent!');
        },
        sayHiToWalk: function () {
            alert('Hi, I am parent! and going to walk!');
        }
    };

    //This is child class and the parent class is inherited in the child class.
    var child = Object.create(parent);

    child.sayHi = function () {
        alert('Hi, I am a child!');
    };

<button type="submit" onclick="child.sayHi()"> click to oops</button>

The output is : Hi, I am a child!

Wednesday, June 10, 2015

How to make google map in angular js?

     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
    <script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=en"></script>
    <style>
        #googleMap {
            height: 800px;
            width: 800px;
            box-shadow: 3px 3px 10px gray;
        }
    </style>
    <div ng-app="googleAapApp" ng-controller="googleAapCtrl">

        <div id="googleMap"></div>
    </div>
     
  <script>

      var cities = [{
          city: 'India',
          desc: 'The Indian economy is the world seventh-largest by nominal GDP and third-largest by purchasing power parity (PPP).',
          lat: 23.200000,
          long: 79.225487
      }, {
          city: 'New Delhi',
          desc: 'Delhi, officially the National Capital Territory of Delhi, is the Capital territory of India. It has a population of about 11 million and a metropolitan population of about 16.3 million',
          lat: 28.500000,
          long: 77.250000
      }, {
          city: 'Mumbai',
          desc: 'Mumbai, formerly called Bombay, is a sprawling, densely populated city on India’s west coast',
          lat: 19.000000,
          long: 72.90000
      }, {
          city: 'Kolkata',
          desc: 'Kolkata is the capital of the Indian state of West Bengal. It is also the commercial capital of East India, located on the east bank of the Hooghly River',
          lat: 22.500000,
          long: 88.400000
      }, {
          city: 'Chennai   ',
          desc: 'Chennai holds the colonial past and is an important city of South India. It was previously known as Madras',
          lat: 13.000000,
          long: 80.250000
      }, {
          city: 'Gorakhpur',
          desc: 'Gorakhpur also known as Gorakhshpur is a city along the banks of Rapti river in the eastern part of the state of Uttar Pradesh in India, near the Nepal border 273 east of the state capital Lucknow',
          lat: 26.7588,
          long: 83.3697
      }];

      //Create angular controller.
      var app = angular.module('googleAapApp', []);
      app.controller('googleAapCtrl', function ($scope) {
          $scope.highlighters = [];
          $scope.gMap = null;

          var winInfo = new google.maps.InfoWindow();

          var googleMapOption = {
              zoom: 4,
              center: new google.maps.LatLng(25, 80),
              mapTypeId: google.maps.MapTypeId.TERRAIN
          };

          $scope.gMap = new google.maps.Map(document.getElementById('googleMap'), googleMapOption);

          var createHighlighter = function (citi) {
              var citiesInfo = new google.maps.Marker({
                  map: $scope.gMap,
                  position: new google.maps.LatLng(citi.lat, citi.long),
                  title: citi.city
              });
              citiesInfo.content = '<div>' + citi.desc + '</div>';
              google.maps.event.addListener(citiesInfo, 'click', function () {
                  winInfo.setContent('<h1>' + citiesInfo.title + '</h1>' + citiesInfo.content);
                  winInfo.open($scope.gMap, citiesInfo);
              });
              $scope.highlighters.push(citiesInfo);
          };

          for (i = 0; i < cities.length; i++) {
              createHighlighter(cities[i]);
          }
      });

    </script>