ng包含一个src变量。

时间:2022-08-25 23:53:55

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

我想用一个变量来改变ng-includes src。目前这是我所拥有的。

 <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?

不幸的是,我不能使用ng-view,因为它已经被用于访问这个页面。有可能做这样的东西吗?

2 个解决方案

#1


50  

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

#2


10  

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

像这样。您需要使用单引号和+,就像在JavaScript中那样。

<ng-include src="'/path/to/template'+ my.variable +'.html'"></ng-include>

#1


50  

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

#2


10  

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

像这样。您需要使用单引号和+,就像在JavaScript中那样。

<ng-include src="'/path/to/template'+ my.variable +'.html'"></ng-include>