1

So I am trying to add an ng-include for my side bar content but it is not working.

app.js

...
gvhsApp.controller('MainController', function($scope) {
    $scope.template = 'views/mainSidebar.html';
});

index.html

...
<div class="col-md-4">
    <div ng-include src="template"> </div>
</div>

I am not seeing any errors in my chrome console. Could it be I am not pointing to the file location properly?

Edit:

Directory Structure

app/
   js/
      app.js
   views/
      index.html
      templates/
          mainSidebar.html
build/
   js/
      app.js
   views/
      index.html
      mainSidebar.html

The build directory is where my server is looking at

1
  • You might need to do: <div ng-include src="{{template}}"> </div> Commented Oct 30, 2014 at 2:07

1 Answer 1

1

ng-include doesn't automatically resolve the src value to an expression - it just expects text. Use mustaches inside the value:

<div class="col-md-4">
    <div ng-include src="{{template}}"> </div>
</div>

This of course assumes that the <div> is inside an Angular-enabled view and bound to the controller correctly.

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

1 Comment

The problem was I was not putting that code inside the ng-view. Once I did that it worked

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.