How to route pages with controllers

Routing seems to be very difficult until you try it. But its very pretty simple once you understood the concept.

First of all include angular-route.js file in your html pages

Now in module declare it like shown below

var app = angular.module(‘myApp’, [‘ngRoute’]);

Now just use your routeprovider to finish the task like shown below

app.config(function ($routeProvider) {
$routeProvider
.when(‘/show/:id’, {                        // if you want to pass query string like id,name etc.
templateUrl: ‘show.html’,            // give the template details
controller: ‘showController’      // controller details
}).when(‘/display’, {
templateUrl: ‘display.html’,
controller: ‘displayController’
})

$routeProvider.otherwise(‘/index.html’); //default case
});

 

What for you looking for dude?? thats it. Its done 😀

You can check it now.

Advertisements

One thought on “How to route pages with controllers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s