javascriptangularjsnode.jsangular-ui-bootstrapangular-ui-modal

how to use angular-ui modal templateURL with node/express routing


I'm somewhat confused as to why I get this error. I have a hunch it's with the templateURL and I have tried a few things but to no avail. I have read the documentation and scoured a bunch of SO posts but none of them helped much. I want to use Express/Node to serve up the pages and I have a feeling that's why my templateURL isn't working in app.js.

Here is my index.html with my controller and my template.

<body ng-app="app" ng-controller="AppCtrl">
<script type="text/ng-template" id="pageContent.html">
    <div class="container">
        <div class="modal-header">
            <h3 class="modal-title">I am a modal!</h3>
        </div>
        <div class="modal-body">
            <h1>HELLO</h1>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" type="button" ng-click="cancel()">OK</button>
            <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
        </div>
    </div>
</script>
<div ng-click="open()"> <!-- this is what makes the modal -->
<!-- rest of html below -->

This is what is in app.js

var app = angular.module("app", ["ngAnimate", 'ui.bootstrap']);

app.controller("AppCtrl", function($scope, $timeout, $uibModal, $http) {

    $scope.open = function (person) {
        $scope.selectedPerson = "passed in person";
        console.log($scope.selectedPerson);


        var modalInstance = $uibModal.open({
            templateUrl: 'pageContent.html',
            controller: 'ModalInstanceCtrl',
            resolve: {
                selectedPerson: function() {
                    return $scope.selectedPerson;
                }
            }
        });

    };
});

app.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance, selectedPerson) {

    $scope.selectedPerson = selectedPerson;


    $scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };
});

I have also tried to replace templateURL with template: "<p> hello world </p>" but that also produces same error.

Here is the error trace: enter image description here


Solution

  • Use angular.js instead of angular.min.js to get a clearer error message.

    To resolve this particular problem, you need to use ui-bootstrap-tpls.min.js (or ui-bootstrap-tpls.js) instead of ui-bootstrap.min.js (ui-bootstrap.js).

    After that, you probably have some other issues, but maybe that is then a different SO Question? :-)