• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Routing not working as expected in Angular.js

 
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm consuming an API and have an ng-view in my app that displays 2 views based on the routes. I've cloned the angular-seed repository and wish to build upon it.

I have two different views that I want to route through. "Show" that is based on view1.js and "Ask" that is based on view2.js.

What my problem is that when I fire up the browser and request index.html it should have shown "Show" details as it is declared as such in the "otherwise" clause. But subsequently after a few seconds "Ask" request is also fired and here is where I'm confused as to why it is doing this. Also clicking on links for views in index.html also does not seem to respond and direct me to a view.

Could anyone let me know where I'm going wrong?

Code pasted below. view2.js and view2.html templates not included here as they are more or less same as its view1 counterpart.

app.js


index.html


view1.js


view1.html

 
Ranch Hand
Posts: 243
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But subsequently after a few seconds "Ask" request is also fired



The problem lies in this piece of code in view1.html.



You've added a controller to the section of the DOM and the constructor of "View2Ctrl" is being called.

Also clicking on links for views in index.html also does not seem to respond and direct me to a view.


which links in here ?

Thanks
Srikkanth
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great find. This should do it.

Also clicking on links for views in index.html also does not seem to respond and direct me to a view.



I meant the routes placed inside the <a> tag.

Thanks a ton.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ahsan Bagwan wrote:
I meant the routes placed inside the <a> tag.



I"m still not sure which links you're talking about. Links to view1 and view2 ?

Thanks
Srikkanth
 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ahsan Bagwan wrote:

Also clicking on links for views in index.html also does not seem to respond and direct me to a view.



I meant the routes placed inside the <a> tag.



I think Ahsan talks about those links:


Ahsan, by "clicking on links for views does not seem to respond and direct me to a view" you mean that the web page is not being reloaded/redirected, but the view is being displayed right away without the page reload? If yes, this is exactly the correct behavior of routing in Angular. The idea is to load views without need of page reload.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Adam. I was a bit rusty with the terminologies.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic