[英]Load Angular's UI Bootstrap modal with dynamic content
我正在尝试使用Angular和UI Bootstrap使模态动态加载模板,但是我什至不知道该怎么做。
这是我到目前为止的代码:
小提琴 : https : //jsfiddle.net/fwpcsfg7/8/
我想要的是以下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>
我想为每个item.type
值显示一个具有不同内容的模式。 如果您能给我一个基本的小提琴,我希望。
现实生活中的情况更加复杂,因此我需要将模态的内容作为模板加载(也许更容易为每个item.type
创建模态)。
编辑:我不知道如何解决的问题之一是:如果我在另一个完全不同的控制器上,如何访问item
属性?
在使用angular js单击时如何将html模板附加到div /指令是否会有所帮助?
有一些X变量来指示要加载的模板。 并使用ng-include和src =“ X”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.