【问题标题】:ng-include with a variable for srcng-include 与 src 的变量
【发布时间】:2014-03-18 14:05:55
【问题描述】:

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

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

这里是控制器:

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

不幸的是,我不能使用 ng-view,因为它已经被用来让我进入这个页面。 有可能做这样的事情吗?

【问题讨论】:

  • 你试过 ng-src="{{view}}" 吗?

标签: javascript angularjs angularjs-ng-include


【解决方案1】:

尝试如下:

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

------------------或----------

你可以这样做,

查看:

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

控制器:

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

【讨论】:

  • &lt;div data-ng-include data-ng-src="getPartial()"&gt;&lt;/div&gt; 对我不起作用。 getPartial() 没有上升,但 &lt;ng-include src="getPartial()"&gt;&lt;/ng-include&gt; 有效!
  • @Chaki_Black 尝试使用&lt;div ng-include src="getPartial()"&gt;&lt;/div&gt; 而不是&lt;div data-ng-include data-ng-src="getPartial()"&gt;&lt;/div&gt;
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2014-10-07
    • 2017-11-24
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2016-07-05
    • 2013-09-29
    • 1970-01-01
    • 2015-02-17
    相关资源
    最近更新 更多