Wednesday, March 23, 2016

                       Useful Modules with Angular for large                                                               applications



I have listed some of the important modules which are useful when working with large application with angular.Each module is having some basic information given here.To see more information you can click on more info click given under each module.

1).RequireJs: 

While working with large application  we do have several JavaScript files independent of each other in functionality,here RequireJs comes in picture.
RequireJS needs a main file that contains the basic configuration data such as paths to modules and shim.

Main.js  //Add this in your master page

 require.config({  
   baseUrl: "",  
   urlArgs: "v=1.0", //Maintain the version   
   waitSeconds: 60,  
   paths: { // Path of the js file here  
   'angular': 'content/angularlib/angular',  
   'angularAMD': ''  
   content / angularlib / angularAMD '  
   },  
   shim: { //Modules and their dependent modules  
   'angularAMD': ['angular'], //here angularAMD is dependent on angular  
   }  
 }); 

In your controller access the Javascript files you want

 define(['angular'], function($filter,$timeout){  
  function calculateSalary() {  
   // Can use the dependency objects received above  
  }  
 })

MoreInfo

2).angularAMD:

AngularAMD’s reason for existence is to facilitate using RequireJS with Angular, and lazy loading portions of your application.Along with the main.js file we would also require App.js common file for application.
Notice we have added the app dependency in main.js file at last


 require.config({  
   baseUrl: "",  
   urlArgs: "v=1.0",   
   waitSeconds: 60,  
   paths: {   
   'angular': 'content/angularlib/angular',  
   'angularAMD': '' content / angularlib / angularAMD '  
   },  
   shim: { //Modules and their dependent modules  
   'angularAMD': ['angular'], //here angularAMD is dependent on angular  
   }  
  // Say we have a dep on App, so it gets loaded  
   deps: ["app"]  
 });  

In App,js

 define(['angularAMD', 'angular-route'], function (angularAMD) {  
   var app = angular.module("webapp", ['ngRoute']);  
      //app contanstant,confif, on app run setting would be here   
   });  
   return angularAMD.bootstrap(app);  
 });  

Now you can use this app object throughout the application to register controllers ,services etc.

MoreInfo

3).ngRoute:

This module is used for routing between different views in your application.Whenever the url changes it will check the routeProvider and navigate to the template and load the controller.If no route matches it routescto the defalut page.

You can register your routes in config in App.js file and inject dependency of 'ngRoute'



 define(['angularAMD', 'angular-route'], function (angularAMD) {  
   var app = angular.module("webapp", ['ngRoute']);  
      // configure our routes  
   app .config(function($routeProvider) {  
     $routeProvider  
       // route for the home page  
       .when('/', {  
         templateUrl : 'pages/home.html',  
         controller : 'mainController'  
       })  
       // route for the about page  
       .when('/about', {  
         templateUrl : 'pages/about.html',  
         controller : 'aboutController'  
       })  
       // route for the contact page  
       .when('/contact', {  
         templateUrl : 'pages/contact.html',  
         controller : 'contactController'  
       });   
     .otherwise({ redirectTo: '/' });//default ie home  
   });  
   return angularAMD.bootstrap(app);  
 });  

MoreInfo

4).angular-translate

This module helps angular application to support i18n(internationalization ) and l10n(localization).
First you need to inject angular-translate module as a dependency into your app

 var app = angular.module('myApp', ['pascalprecht.translate']);



config setting:


  app.config(['$translateProvider', function ($translateProvider) {  
  $translateProvider.translations('en', {  
   'TITLE': 'Hello',  
   'FOO': 'This is a paragraph'  
  });  
  $translateProvider.translations('de', {  
   'TITLE': 'Hallo',  
   'FOO': 'Dies ist ein Absatz'  
  });   
  $translateProvider.preferredLanguage('en');  
 }]);  

How to use in access in HTML file


 <h1>{{ 'TITLE' | translate }}</h1>  
 <p>{{ 'FOO' | translate }}</p> 


Even we can have our different language files and use them according to the language selection.


MoreInfo

5).ui-bootstrap:

This module supports the angular directives based on Bootstrap's markup and CSS.
There are different directives in this module.Using this module in app helps to have  uniformity
in design and css a throughout application and its also responsive  .

Following are different  day-today used controls supported by ui-bootstrap directives
  • Accordion
  • Alert
  • Buttons
  • Carousel
  • Collapse
  • Datepicker
  • Dropdown
  • Modal
  • Pagination
  • Popover
MoreInfo

6).UI-grid:

This is an angular grid.Ui-grid can be used to display data in grid format.

It support all following features

  • Performs well with large data sets evn 10000+ rows
  • Pagination
  • Multiple row selection with Ctrl and Shift keys,
  • column Resizing,
  • row editing,
  • Grouping,
  • Infinite scroll,
  • hiding/showing columns etc
Inject dependency for angular ui-grid 

 var app = angular.module('myApp', ['ui.grid']);  
7).angular-moment:

angular-moment provides angular directive and filter for Moment Js.
This requires moment js to be loaded first in your app.Moment js provides facilities
operation on date ,its localization and timezone
In app.js file on app.run event change the local which will be applicable to the dates used in your app and will localized.

 App.js  
 myapp.run(function(amMoment) {  
   amMoment.changeLocale('de');  
 });   


There are some more:)

  • angular-cookies:To store and get data from cookies. MoreInfo
  • blockUi:Loader in application.MoreInfo
  • isteven-multi-select:multiselect selct dropdown with grouping,search facility.MoreInfo
You can search popular angular modules here

and more are coming.......




Call Webmethod using Json

function JsoncallResult() {
                var Result = "";
                var params = { PatientID: PatientID, LocationID: LocationID, TransDate: TransDate };

                $.ajax({
                    type: "POST",
                    url: "/DesktopModules/DMS/JsonCalls.aspx/GetPatient",
                    data: JSON.stringify(params),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: false,
                    cache: false,
                    success: function (data) {
                        Result = data.d; 
                    },
                    error: function (result) {
                        alert('error occured');
                        alert(result.responseText);

                    }

                });
               return Result;
            }

Monday, April 14, 2014

Position in CSS



Different Types of Position in CSS:

  • Static. This is the default for every single page element. Different elements don't have different default values for positioning, they all start out as static. Static doesn't mean much, it just means that the element will flow into the page as it normally would. The only reason you would ever set an element to position: static is to forcefully-remove some positioning that got applied to an element outside of your control. This is fairly rare, as positioning doesn't cascade.
     
  • Relative. This type of positioning is probably the most confusing and misused. What it really means is "relative to itself". If you set position: relative; on an element but no other positioning attributes (top, left, bottom or right), it will no effect on it's positioning at all, it will be exactly as it would be if you left it as position: static; But if you DO give it some other positioning attribute, say, top: 10px;, it will shift it's position 10 pixels DOWN from where it would NORMALLY be. I'm sure you can imagine, the ability to shift an element around based on it's regular position is pretty useful. I find myself using this to line up form elements many times that have a tendency to not want to line up how I want them to.
    There are two other things that happen when you set position: relative; on an element that you should be aware of. One is that it introduces the ability to use z-index on that element, which doesn't really work with statically positioned elements. Even if you don't set a z-index value, this element will now appear on top of any other statically positioned element. You can't fight it by setting a higher z-index value on a statically positioned element. The other thing that happens is it limits the scope of absolutely positioned child elements. Any element that is a child of the relatively positioned element can be absolutely positioned within that block. 

  • Absolute. This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. Remember that these values will be relative to the next parent element with relative (or absolute) positioning. If there is no such parent, it will default all the way back up to the <html> element itself meaning it will be placed relatively to the page itself.
    The trade-off, and most important thing to remember, about absolute positioning is that these elements are removed from the flow of elements on the page. An element with this type of positioning is not affected by other elements and it doesn't affect other elements. This is a serious thing to consider every time you use absolute positioning. It's overuse or improper use can limit the flexibility of your site.

  • Fixed. This type of positioning is fairly rare but certainly has its uses. A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn't change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled, creating an effect a bit like the old school "frames" days. Take a look at this site (update: dead link, sorry), where the left sidebar is fixed. This site is a perfect example for since it exhibits both good and bad traits of fixed positioning. The good is that it keeps the navigation present at all times on the page and it creates and interested effect on the page. The bad is that there are some usability concerns. On my smallish laptop, the content in the sidebar is cut off and there is no way from me to scroll down to see the rest of that content. Also if I scroll all the way down to the footer, it overlaps the footer content not allowing me to see all of that. Cool effect, can be useful, but needs to be thoroughly tested.