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?

有帮助吗?

解决方案

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';
  }
}

其他提示

Like this. You need to use single quotes and +, like you would in JavaScript.

<ng-include src="'/path/to/template'+ my.variable +'.html'"></ng-include>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top