Angularjs ngRoute example

Angularjs ngRoute example, angularjs tutorial, angularjs

What is an Angularjs Routing?
If you want to move a different pages in your web-application, but you want to a your application to be a Single page application, here the pages are not loaded. Here we can use a ngRoute module.

The ngRoute module can routes the different pages in your application without any reloading

Simple example :

you can includes below two scripts in header tag

<script src=”” ></script>
<script src=”” ></script>

Know you can Create html page

<!DOCTYPE html>
<script src=””></script>
<script src=””></script>

<body ng-app=”yourApp”>

<p><a href=”#/”>Main</a></p>

<a href=”#first”>FirstPgae</a>
<a href=”#secound”>SecoundPage</a>
<a href=”#third”>ThirdPage</a>

<div ng-view></div>

var app = angular.module(“yourApp”, [“ngRoute”]);
app.config(function($routeProvider) {
.when(“/”, {
templateUrl : “.htm”
.when(“/first”, {
templateUrl : “firstpage.htm”
.when(“/secound”, {
templateUrl : “secoundpage.htm”
.when(“/third”, {
templateUrl : “thirdpage.htm”

<p>Click on the links to navigate to “firstpage.htm”, “secoundpage.htm”, “thirdpage.htm”, or back to “main.htm”</p>

simple Example 2:

<script src=”” ></script>
<script src=”” ></script>
<script type=”text/javascript” src=”yourapp.js”></script>
<style type=”text/css”>
<body ng-app=”yourapp”>
<div class=”row”>
<div class=”col-sm-14 well”>
<div class=”row”>
<div class=”col-sm-4 well” style=”height:100%”>
<li><a href=’#/first-page’>Firstpage</a></li>
<li><a href=’#/second-page’>Secondpage</a></li>
<li><a href=’#/third-page’>Thirdpage</a></li>
<div class=”col-sm-10 well” style=”height:100%”>
<div ng-view></div>


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

app.config([‘$routeProvider’, function($routeProvider){
.when(‘/first-page’, {
templateUrl: ‘page.htm’,
controller: ‘page1’,
caseInsensitiveMatch: true //case insensitive route
.when(‘/second-page’, {
templateUrl: ‘page2.htm’,
controller: ‘page2’
.when(‘/third-page’, {
template: ‘<strong>this is third page (with no template)</strong>’,
//redirectTo: ‘/first-page’ //redirects to this route (no template shown) – optional
redirectTo: function(params, path, search){ //just another way of redirection
// console.log(path);
// console.log(search);
// console.log(params);

alert(‘Sorry! not implemented yet…will take you to first message now’);
return ‘/first-page’;
template: ‘<strong>click one of the links from left panel </strong>’
template: ‘<strong>No content available one of the links from left panel</strong>’
//.otherwise(‘/’) //or redirect to root

app.controller(‘page1’, [‘$scope’, function($scope){
$scope.aa = 90;
$ = 200;

app.controller(‘page2’, [‘$scope’, function($scope){
$ = 100;
$scope.dd = 200;

this is from msg1 template
a = {{aa}}, b = {{bb}}

this is from msg2 template
c = {{cc}}, d = {{dd}}

70 thoughts on “Angularjs ngRoute example”

  1. It is the best time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I want to suggest you some interesting
    things or advice. Maybe you can write next articles referring to this article.
    I desire to read more things about it!

  2. I simply want to mention I am newbie to blogging and site-building and really enjoyed this web page. Likely I’m likely to bookmark your blog post . You certainly have amazing articles and reviews. Appreciate it for sharing your blog site.

  3. There are some attention-grabbing points in time on this article but I don’t know if I see all of them heart to heart. There’s some validity however I will take maintain opinion till I look into it further. Good article , thanks and we would like more! Added to FeedBurner as well

  4. I enjoy you because of your whole work on this website. Betty delights in engaging in investigation and it’s really simple to grasp why. A lot of people hear all about the powerful medium you create valuable strategies by means of the blog and as well improve participation from others about this article then our simple princess is now discovering a whole lot. Take pleasure in the rest of the year. You are always doing a remarkable job.

  5. I simply want to mention I’m new to weblog and actually loved your page. More than likely I’m likely to bookmark your website . You amazingly come with amazing stories. Kudos for sharing your webpage.

  6. With havin so much written content do you ever run into any problems of plagorism or copyright infringement? My website has a lot of exclusive content I’ve either written myself or outsourced but it seems a lot of it is popping it up all over the web without my agreement. Do you know any ways to help prevent content from being ripped off? I’d really appreciate it.

  7. I wish to show thanks to you just for bailing me out of this particular situation. As a result of searching throughout the search engines and meeting advice that were not helpful, I believed my entire life was done. Being alive devoid of the strategies to the issues you have resolved as a result of your entire guide is a crucial case, and the kind that would have badly affected my career if I had not discovered your web site. Your knowledge and kindness in controlling all areas was excellent. I am not sure what I would’ve done if I had not discovered such a step like this. It’s possible to at this moment look forward to my future. Thank you so much for your impressive and effective guide. I will not think twice to propose the blog to anybody who needs and wants guidance on this issue.

  8. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is excellent blog. A fantastic read. I will definitely be back.

  9. I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this increase.

  10. The very next time I read a blog, Hopefully it does not fail me as much as this one. I mean, I know it was my choice to read through, nonetheless I genuinely thought you would probably have something useful to talk about. All I hear is a bunch of crying about something you can fix if you were not too busy looking for attention.

  11. This design is spectacular! You most certainly know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job. I really loved what you had to say, and more than that, how you presented it. Too cool!

  12. I think this is one of the most vital information for me. And i am glad reading your article. But want to remark on few general things, The website style is great, the articles is really great : D. Good job, cheers

  13. Can I just say what a reduction to search out someone who actually is aware of what theyre speaking about on the internet. You positively know learn how to carry a difficulty to gentle and make it important. Extra individuals have to learn this and understand this aspect of the story. I cant believe youre not more standard since you positively have the gift.

  14. I am usually to blogging and i actually admire your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

  15. A domain name name, or Web address, is an deal with where it is easy to be observed online. It’s how you’ll communicate yourself by means of email or your site and it’s which buyers assume of once attempting to discover you.

  16. I simply want to say I am just newbie to blogging and absolutely enjoyed this web page. More than likely I’m want to bookmark your site . You absolutely have tremendous articles. Many thanks for revealing your website page.

  17. I have been looking around for an article like this. Took some time but finally found it… Really good read thanks. It’s been difficult to find the information I needed. I use this website for a good deal.

  18. Good post made here. One thing I’d like to say is the fact most professional domains consider the Bachelor’s Degree like thejust like the entry level standard for an online certification. Even though Associate Diplomas are a great way to get started on, completing your Bachelors opens many entrance doors to various jobs, there are numerous online Bachelor Course Programs available coming from institutions like The University of Phoenix, Intercontinental University Online and Kaplan. Another concern is that many brick and mortar institutions provide Online types of their college diplomas but typically for a greatly higher charge than the corporations that specialize in online college degree programs.

  19. There are certainly a lot of details like that to take into consideration. That could be a great level to carry up. I offer the thoughts above as normal inspiration but clearly there are questions like the one you bring up where a very powerful thing might be working in honest good faith. I don?t know if finest practices have emerged around issues like that, but I’m sure that your job is clearly recognized as a good game. Each girls and boys really feel the impact of only a moment’s pleasure, for the rest of their lives.

  20. Hey there, I think your website might be having browser compatibility issues. When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!

  21. Magnificent goods from you, man. I’ve understand your stuff previous to and you are just too excellent. I really like what you have acquired here, certainly like what you are stating and the way in which you say it. You make it entertaining and you still take care of to keep it smart. I can not wait to read much more from you. This is really a terrific site.

  22. Hi this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!Rosemarie Orduno

  23. Pingback: My Homepage
  24. It is indeed my belief that mesothelioma will be the most lethal cancer. It has unusual traits. The more I really look at it a lot more I am confident it does not act like a true solid tissues cancer. In the event mesothelioma is a rogue virus-like infection, in that case there is the chance of developing a vaccine plus offering vaccination for asbestos exposed people who are really at high risk with developing future asbestos connected malignancies. Thanks for giving your ideas on this important ailment.

  25. Thanks a lot for providing individuals with such a brilliant possiblity to check tips from this site. It is usually so enjoyable and as well , full of a good time for me personally and my office mates to visit your web site not less than 3 times weekly to learn the new things you have got. And definitely, I am certainly pleased for the outstanding methods you give. Some 4 facts in this article are easily the most impressive we have ever had.

  26. I discovered your weblog site on google and examine just a few of your early posts. Proceed to keep up the very good operate. I just further up your RSS feed to my MSN News Reader. Seeking ahead to studying extra from you afterward!…

  27. Superb site you have here but I was wanting to know if you knew of any message boards that cover the same topics talked about in this article? I’d really love to be a part of group where I can get suggestions from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Appreciate it!

  28. Thank you for another informative website. Where else could I get that kind of info written in such an ideal way? I have a project that I’m just now working on, and I have been on the look out for such information.

Leave a Reply

Your email address will not be published.