如何动态设置`ng-include`路径?

时间:2022-06-10 11:29:15

I have a content with 8 blocks in the page. when user clicks on each, I am opening a pop-up and showing the same content there. so I have 8 popup contents separately.

我在页面中有8个块的内容。当用户点击每个时,我打开一个弹出窗口并在那里显示相同的内容。所以我分别有8个弹出内容。

When each of the block clicked i am making that view as true. so according to the current view, i would like to change the pop-up (include) content to be changed. but not working.

当点击每个块时,我将该视图设为true。所以根据当前的观点,我想更改要更改的弹出(包含)内容。但没有工作。

here is my pop-up : html:

这是我的弹出窗口:html:

<div class='ng-modal' ng-if="modal.isOpen">
    <div class='ng-modal-overlay' ng-click='modal.hide()'></div>
        <div class='ng-modal-dialog' ng-style='dialogStyle'>
        <div class='ng-modal-dialog-content'>
         <ng-include ng-if="modal.board1" src="'../views/projectSummary/modals/{{currentView}}.html'"></ng-include>
         {{currentView}} //it works!
        </div>
    </div>
</div>

in my controller i am setting :

在我的控制器中,我正在设置:

$scope.currentView = "board1";

so, my html let load from :

所以,我的html加载来自:

'../views/projectSummary/modals/board1.html'

Click here to see my Error :

点击这里查看我的错误:

2 个解决方案

#1


2  

It's better/cleaner to set the URL of the partial in the controller, so this becomes a non-issue and you could just do:

在控制器中设置部分的URL更好/更清洁,所以这成为一个非问题,您可以这样做:

<ng-include src="currentViewURL">

but to answer your question:

但要回答你的问题:

<ng-include src="'../views/projectSummary/modals/' + currentView + '.html">

#2


2  

Since 1.2 you can only bind one expression to *[src], *[ng-src] or action. You can read more about it here.

从1.2开始,您只能将一个表达式绑定到* [src],* [ng-src]或action。你可以在这里读更多关于它的内容。

Write a function in your scope to return the concatenated result:

在范围内编写一个函数以返回连接结果:

$scope.getSrc = function (viewName) {
  return '../views/projectSummary/modals/' + viewName + '.html';
};

#1


2  

It's better/cleaner to set the URL of the partial in the controller, so this becomes a non-issue and you could just do:

在控制器中设置部分的URL更好/更清洁,所以这成为一个非问题,您可以这样做:

<ng-include src="currentViewURL">

but to answer your question:

但要回答你的问题:

<ng-include src="'../views/projectSummary/modals/' + currentView + '.html">

#2


2  

Since 1.2 you can only bind one expression to *[src], *[ng-src] or action. You can read more about it here.

从1.2开始,您只能将一个表达式绑定到* [src],* [ng-src]或action。你可以在这里读更多关于它的内容。

Write a function in your scope to return the concatenated result:

在范围内编写一个函数以返回连接结果:

$scope.getSrc = function (viewName) {
  return '../views/projectSummary/modals/' + viewName + '.html';
};