Skip to main content

Posts

Showing posts from September, 2015

$scope vs $rootScope in AngularJs

What is $scope? The angular $ scope  is a JavaScript object which provide the connectivity between the controller and the view. All the model data bind on view (DOM element) using the $scope for a controller. What is $rootScope? The angularjs $ rootScope  is the scope and one application can have only one $rootScope and It use like global variable and access in across application. The angular $rootScope is parent scope and $scopes are child scopes. $scope vs. $rootScope The $rootScope objects updates under a specific controller $scope not for all global controllers. The angular $scope can't be used outside the controller and its only for current controller but the $rootScope can be used anywhere and Its available globally in the application. All app has one-and-only $rootScope and its lifecycle is the same as the app and its all controllers can have. The $apply and $watch are scope methods. You can see the worki

What is a placeholder attribute in HTML5?

Its use for hint of input text field like water mark of Ajax. i.e. Live demo example  http://embed.plnkr.co/5hIPdx/preview Syntax:  < input   type =”text”   id =”ids”   placeholder =”text here..”> Example in detail as given below. < !DOCTYPE html > < html > < head >     < meta charset ="utf-8" />     < title > html5 input textplaceholder </ title >     < link rel ="stylesheet" href ="style.css" />     < script src ="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"> </ script > </ head > < body >     < p > HTML5 input text placeholder </ p >     < form >         < div >             < div >                 < input type ="text" name ="txtName" placeholder ="Enter Name" class ="tb8">             </ div >             <

What is a draggable attribute in HTML5?

The draggable attribute are  used to drag the attributes from one location to other. In HTML5,  by  default draggable is true for the some attribute and some or not. i.e. < span   draggable =”true”>

What is Web Worker in HTML5?

When some scripts are executing in HTML page that time page is going to blocking for a moment but in HTML5 have a Web Worker process to solved this blocking issues and by this blocking script send to background process. For this features user can  freely access the page without blocking. But some JavaScript objects are not accessible to HTML5 web worker like. Parent object. Window object. Document object. Thank you! Anil

How to enable cache in HTML5?

Using   manifest   we can cache the file in   HTML5 . The manifest is a text file which used to decide the where the file is cache. These applies when the application cache is enabled. < !doctype   html > < html   manifest =”myManifesrTest.appCache”>    //TODO </ html > There are 4 sections of manifest to cache  the file. cache manifest : is cache the version information cache : it contain the html, css and jQuery file etc. network : its contain the network info fallback : it contain offline html

What is sessionStorage in HTML5?

The sessionStorage is   HTML5  features and used to store data in the client browsers but store data for one session. If browser is closed that time data is lost. window.sessionStorage myStore[ 'sessionStorage' ] =   function (key, val) {     try   {         sessionStorage.setItem(key, val);         sessionStorage.removeItem(key);           return   true ;     }       catch (e) {         return   false ;     } };

What is localStorage in HTML5?

The localStorage  is   HTML5  features and used to store data in the client brewers. If browser is closed that time it does not lost data. Its work with key and values pairs. i.e. localStorage.setItem( "email" ,   "anil.singh@gmail.com" ); Here key is email and its values is anil.singh@gmail.com.  It is stores data with no expiration date. Before HTML 5 we can achieve using cookies. The example for localStorage as given below myStore[ 'localstorage' ] =   function () {     try   {         localStorage.setItem(key, val);         localStorage.removeItem(key);           return   true ;     }       catch (e) {         return   false ;     } }; The Advantages over localStorage as given below  No loss data event browser is closed. localStorage    have good performance then cookies. localStorage store the data for longer period localStorage    is more secure then cookies.

What is doctype in HTML5?

The doctype  is not a HTML  tag and Its provide the instruction to the web browsers about what version of HTML page is going to written(load). The   < !doctype   html >   must be declare before the   < html >   tag and it's not case sensitive. The browser use this doctype information to render page correctly. The doctype  not have the opening and closing tag like html.

How to prevent/stop form submission?

we can use preventDefault() Event Method. //Example, use of prevent default. JavaScript     document.getElementById( "chkb" ).addEventListener( "click" , function (event) {         event.preventDefault()     }); jQuery     $( function () {         $( '#form' ).on( 'submit' , function (ev) {             ev.preventDefault();         });     });

How to know the total number elements present in an array?

We can use sizeof () method and length. For example you can seen below.      // define an object for sizeof().     var sofObject =         {             'boolean' : true ,             'number' : 1,             'array' : [1, 2, 3]         };     // Get the size of the "sofObject" object.     var size = sizeof (sofObject);      //OR     var object = [];     var size = object.length;

search id and class in jQuery

We can use . find () method.  Please example as given below.     var formElements = $( "li" );     var inputIdsAndClass = $( "input" ).find(formElements);