What is the lifecycle of an AngularJS Controller?

Can someone please clarify what the lifecycle of an AngularJS controller is? Is a controller a singleton, or created / destroyed on demand? If the latter, what triggers the creation / destruction of the controller? Consider the below example: var demoApp = angular.module('demo') .config(function($routeProvider, $locationProvider) { $routeProvider .when('/home', {templateUrl: '/home.html', controller: 'HomeCtrl'}) .when('/users',{templateUrl: '/users.html', controller: … Continue reading What is the lifecycle of an AngularJS Controller?

Angular $http POST request with request payload or form data

If you have RESTful API's on your server side and are trying to use Angular's $http service to consume the resource, you should be careful about how the request (for example, Http POST) is made, in particular how the data (perhaps in the format of form) is included in the request. As a JSON object … Continue reading Angular $http POST request with request payload or form data

HTTP request in Node.js or other JavaScript framework

You should always consider using the Object provided by the MV* framework. If the JS framework doesn't have a built-in support for communicating with the server (which I highly doubt), you can opt to work directly with the low-level methods of the XMLHttpRequest object itself or use a general utility library such as JQuery. On … Continue reading HTTP request in Node.js or other JavaScript framework

Fixing the Back Button: A Simple SPA Behavior using Location Hash

Introduction Using a SPA framework, like AngularJS, is overkill for a simple one-page website. But, suppose that single web page has pseudo-navigation needs, like a dialog that opens in response to the user clicking a button. This represents a state transition, and clicking the back button in the browser (or on an Android or Windows Phone) … Continue reading Fixing the Back Button: A Simple SPA Behavior using Location Hash