Wednesday, December 30, 2015

Angular timeout ($timeout) service promise

In angular JS, if you want perform some action after some time (or you want to wait for some time) you can use $timeout service. This service returns the promise which we can resolve by "then". In following example, it will take 2 seconds to call the function "toBeCalled".


function Controller($timeout) {

           wait(2).then(function () {

            })

            function wait(seconds) {
                return $timeout(toBeCalled, seconds * 1000);
            }

            function toBeCalled() {
                console.log("called after 2 seconds");
            }
        }

Saturday, December 19, 2015

Entity Framework Code First Approach

Code First approach does not actually Mean that you can not utilize existing database. Instead, it lets you deal with existing database or you can start with code and Entity Framework will create new database. Let us See both approaches,

Existing Database

Open your project in Visual Studio 2013 and click Add New Item -> ADO.NET Entity Model
Click on the Code First from database option. This wizard will lead you to create model classes.

Wednesday, December 16, 2015

ASP.NET Web API 2 Tips and Tricks

Web API Supports RPC(Remote Procedure Call) API and REST API(Representational State Transfer). To simplify this, RPC means action based routing and REST API means Default GET/POST/.... Methods.
REST API offers only method per request type except the Get which comes two times (One for getting Single Record and one for all Records).

Note: You can not use both techniques in One Controller. you can use One only one technique in one controller.

Configuration


Tuesday, December 15, 2015

How to Know when your angular rendering is complete (Callback function for ngrepeat/ng-repeat)

There are scenarios when you need to know that angular rendering is complete due to ng-repeat directive. Here we need to understand that the success call back method of $http does not mean your rows are rendered. following is the scenario where we can utilize this ng-repeat callback method,
1- You may need to perform particular Jquery Method after rendering of rows is complete.
2- Format generated rows after they are rendered.
3- I needed this to use data tables object ( $('#tbl').DataTable();) after rendering is complete.

To start with, we need to write an attribute level directive which we can call like,