简体   繁体   English

用动态内容加载Angular的UI Bootstrap模式

[英]Load Angular's UI Bootstrap modal with dynamic content

I'm trying to make a modal dynamically load a template with Angular and UI Bootstrap, but I can't even figure how to do it. 我正在尝试使用Angular和UI Bootstrap使模态动态加载模板,但是我什至不知道该怎么做。

This is the code I've got this far: 这是我到目前为止的代码:

Fiddle : https://jsfiddle.net/fwpcsfg7/8/ 小提琴https : //jsfiddle.net/fwpcsfg7/8/

What I want is having the following ng-repeat : 我想要的是以下ng-repeat

<div ng-app="MyApp" ng-controller="ExampleController as example">
  <!-- load a different template (partial) inside the modal depending on the value of item.type -->
  <div class="someClass" ng-repeat="item in example.items" ng-click="example.loadModal(item.templateName)">Modal {{item.type}}</div>
</div>

<!-- The modal that would change it's content depending on the item type-->
<div class="modal" ng-controller="ModalController as modal" ng-include src="example.modalTemplate+'.html'"></div>

<!-- Defining Angular cached partials -->
<script type="text/ng-template" id="modalType1.html">
  <input ng-model="item.name"></input>
</script>
<script type="text/ng-template" id="modalType2.html">
  <input ng-model="item.name"></input>
  <input ng-model="item.age"></input>
</script>
<script type="text/ng-template" id="modalType3.html">
  <input ng-model="item.name"></input>
  <input ng-model="item.name"></input>
</script>
<script type="text/ng-template" id="modalType4.html">
  <input ng-model="item.name"></input>
  <input ng-model="item.lastName"></input>
  <input ng-model="item.country"></input>
  <input ng-model="item.location"></input>
</script>

I'd like to show a modal with different content for each item.type value. 我想为每个item.type值显示一个具有不同内容的模式。 I'd love if you could give me a basic fiddle. 如果您能给我一个基本的小提琴,我希望。

The real life case is more complex, so I need to load the modal's content as a template (maybe is easier to make a modal for each item.type ?) 现实生活中的情况更加复杂,因此我需要将模态的内容作为模板加载(也许更容易为每个item.type创建模态)。

Edit: One of the problems I don't know how to solve is: How do I access the item properties if I'm on other totally different controller? 编辑:我不知道如何解决的问题之一是:如果我在另一个完全不同的控制器上,如何访问item属性?

May be it will be helpful how to append a html template to a div/directive on click with angular js? 在使用angular js单击时如何将html模板附加到div /指令是否会有所帮助

Have some X variable to indicate what template you want to load. 有一些X变量来指示要加载的模板。 And use ng-include with src="X" 并使用ng-include和src =“ X”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM