1

i have this files under my project and i'm encountring some trouble loading them with ajax and applying angular , here is the plunk : http://plnkr.co/MxXzlenAuGcDy8iljKYX

the problem is that the content of sidebar.html get loaded and the controller gets executed correctly but for products.html the content only gets loaded and the controller doesn't get executed. i am using this under chrome and i don't get any errors in my localhost console

1
  • This all seems very convoluted is there a reason for the manual bootstrap? Check out ng-include which will load the sidebar.html async for you and ngRoute (need to include angular-route.js to use this) for handling the navigation for a single view, if you need nested views check out ui-router. Commented Mar 16, 2014 at 17:49

1 Answer 1

1

I put together a modified version of your plnkr to show how I would approach this in general with Angular and dropped out jQuery since it wasn't necessary here:

http://plnkr.co/edit/QgPUk1JMP1vaWtwgXGbw

HTML

<!DOCTYPE html>
<html>

  <head>
    <title></title>
    <script data-require="[email protected]" src="http://code.angularjs.org/1.2.14/angular.js" data-semver="1.2.14"></script>
    <script data-require="[email protected]" src="http://code.angularjs.org/1.2.14/angular-route.js" data-semver="1.2.14"></script>
    <script type="text/javascript" src="script.js"></script>
    <script type="text/javascript" src="category.js"></script>
    <script type="text/javascript" src="products.js"></script>
  </head>

  <body ng-app="myApp">
    <div ng-include="'sidebar.html'"></div>
    <div ng-view></div>
  </body>

</html>

JS

// Code goes here
var app = angular.module("myApp" , ["ngRoute"]);

app.config(function($routeProvider){
  $routeProvider
    .when("/products/:prodId",{templateUrl:"products.html"})
    .when("/products",{templateUrl:"products.html"})
    .when("/", {templateUrl:"home.html"})
    .otherwise({redirectTo:"/"});
  })
Sign up to request clarification or add additional context in comments.

3 Comments

what i've putted in plnkr is just a mini version of my project , when i try to apply this, the app crashes like there is an infinite loop somewhere , when i go to "#/" but with "#/products" it works correctly
Check through your products.html and categories.html files and make sure they aren't also loading the scripts, if you can show the issue in a plunker I can help debug further.
thanks a lot i had a problem in home.html where there was another ng-view i forgot it there by mistake

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.