Search code examples
javascriptangularjsangularjs-ng-include

ng-include with a variable for src


I would like to change the ng-includes src with a variable. Currently this is what I have.

 <div class='alignRightCenter' id='rightContent'>
    <ng-include src="'{{view}}'"> </ng-include>
</div>

And here is the controller:

ctrl.controller('contentCtrl', ['$scope', function($scope) {
      $scope.view = "partials/setListName.tpl.html";
  }]);

Unfortunately I can not use a ng-view because it is already being used to get me to this page. Is it possible to make something like this work?


Solution

  • Try as follows:

    <ng-include src="view"> </ng-include>
    

    -----------------OR----------------------

    You can do this way,

    View:

    <div data-ng-include data-ng-src="getPartial()"></div>
    

    Controller:

    function AppCtrl ($scope) {
      $scope.getPartial = function () {
          return 'partials/issues.html';
      }
    }