0

I have an AngularJs app with start up page as index.html and I am routing the user to projects page by default. The issue is whenever I click the dropdown-toggle link in my index.html page the projects partial view gets reloaded which shouldn't be. Please see the code below:

Index.html

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
</head>
<body>
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <i class="icon-tasks"></i>
                            <span class="badge badge-grey">4</span>
                        </a> 

<div ng-view></div>
</body>

app.js

 $routeProvider
    .when('/projects',
    {
       controller: 'projectController',
       templateUrl: '/app/views/projects/projects.html'
    })       
    .when('/suppliers',
    {
       controller: 'supplierController',
       templateUrl: '/app/views/suppliers/suppliers.html'
    })       
    .otherwise({ redirectTo: '/projects' });

Also, I tried using $locationProvider.html5Mode(true); to remove the "#" from the URL and the reload got stopped but my url (http://localhost/index.html#/projects) becomes like this http://localhost/projects and I'll get a 404. Any idea how to solve the partial view reload issue?

2
  • Don't use anchor tag and use any span tag to achieve style but if you want anchor tag then use ng-click event and in controller try event.preventDefault() Commented Feb 11, 2014 at 19:07
  • Thanks for your response but as per @aduch answer ui.router worked for me. Commented Feb 12, 2014 at 22:41

1 Answer 1

1

I strongly recommend you to use ui.router to manage subviews, it seems to suit to your needs here.

github here

A good introduction to ui-router

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I never know about the ui.router plugin but after your guidance I used it and the page reload issue has gone away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.