AngularJS modal not displayed when using partial for templateURL

Daniel Bogart picture Daniel Bogart · Aug 28, 2015 · Viewed 8.9k times · Source

I have a modal in a partial file that is loaded into my main view with an ng-include tag, but the template isn't found. I don't see the template being loaded in console or the console network tab. I get the following message: Error: [$compile:tpload] Failed to load template: rxsignalUpdateModal.html

controller:

$scope.open = function (size) {

    var modalInstance = $modal.open({
        animation: $scope.animationsEnabled,
        templateUrl: 'rxsignalUpdateModal.html',
        controller: 'ModalInstanceCtrl',
        size: size
    });
};

view:

<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>

partial:

<!-- 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 -->

Answer

Daniel Bogart picture Daniel Bogart · Aug 28, 2015

The solution required a few changes. I removed the ng-include code, and simply added the full path in the modal instance object:

            var modalInstance = $modal.open({
                animation: true,
                templateUrl: 'app/common/partials/rxsignal-update-modal.html',
                controller: 'ModalInstanceCtrl',
                size: size
            });

Then, in the template partial, I removed the script tags so that it was just html.