我在部分文件中有一个模态,该文件使用ng-include标记加载到我的主视图中,但找不到模板。我没有在控制台或控制台网络选项卡中看到正在加载的模板。我收到以下消息:错误:[$ compile:tpload]无法加载模板:rxsignalUpdateModal.html
控制器:
$scope.open = function (size) {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: 'rxsignalUpdateModal.html',
controller: 'ModalInstanceCtrl',
size: size
});
};
视图:
<div class="col-md-12 col-lg-12">
<div class="h4 invisible"></div>
<div class="rxsignal-chart-bubble" ui-view="rxsignal-chart-bubble"></div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<span class="text-muted panel-title">
{{ Drug.aedrug_name | pascalCaseFilter }} RxSignal
</span>
<button class="btn btn-info btn-mini restoreSortButton pull-right"
ng-click="clearLocalStorage()"
popover-append-to-body="true" popover-trigger="mouseenter"
popover-placement="top" popover="Reload grid with default sorting order">
Restore Default Settings
</button>
<span id="rxsignal-filter-view" ui-view="rxsignal-filter"></span>
</div>
<div class="gridStyle" ng-grid="drugRxsignal.options" id="portfolio-rxsignal-grid"></div>
</div>
</div>
</div>
</div>
<div ng-include="app/drug/partials/drug.rxsignal.update.modal.html"></div>
部分:
<!-- modal -->
<h1> test </h1>
<script type="text/ng-template" id="rxsignalUpdateModal.html">
<div class="modal-header">
<h3 class="modal-title letter-title">Modal Title</h3>
</div>
<div class="modal-body">
<div class="letter-body">
<p>text</p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="cancel()">OK</button>
</div>
</script>
<!-- end modal -->
答案 0 :(得分:4)
解决方案需要进行一些更改。我删除了ng-include代码,只是在模态实例对象中添加了完整路径:
var modalInstance = $modal.open({
animation: true,
templateUrl: 'app/common/partials/rxsignal-update-modal.html',
controller: 'ModalInstanceCtrl',
size: size
});
然后,在模板部分中,我删除了脚本标记,以便它只是html。
答案 1 :(得分:1)
脚本/模板元素(text / ng-template)需要一个前导&#39; /&#39;或id
属性上的其他路径,以使其正常工作。
右:<script type='text/ng-template' id='/my-template.html'>
错误:<script type='text/ng-template' id='my-template.html'>
请参阅plunkr:http://plnkr.co/edit/BA26CP?p=preview
脚本的Angular文档:
https://code.angularjs.org/1.3.18/docs/api/ng/directive/script