javascript - 如何将 angular-ui modal templateURL 与 Node/快速路由一起使用

标签 javascript angularjs node.js angular-ui-bootstrap angular-ui-modal

我对为什么会收到此错误感到有些困惑。我有一种预感,它与 templateURL 有关,我尝试了一些方法但无济于事。我已经阅读了文档并搜索了一堆 SO 帖子,但它们都没有多大帮助。我想使用 Express/Node 来提供页面,我感觉这就是我的 templateURL 在 app.js 中不起作用的原因。

这是我的 index.html 以及我的 Controller 和模板。

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

这是 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');
    };
});

我还尝试用 template: "<p> hello world </p>" 替换 templateURL但这也会产生同样的错误。

这是错误跟踪: enter image description here

最佳答案

使用 angular.js 而不是 angular.min.js 以获得更清晰的错误消息。

要解决此特定问题,您需要使用 ui-bootstrap-tpls.min.js(或 ui-bootstrap-tpls.js)而不是 ui-bootstrap.min.js (ui-bootstrap.js).

在那之后,您可能还有一些其他问题,但也许那是一个不同的 SO 问题? :-)

关于javascript - 如何将 angular-ui modal templateURL 与 Node/快速路由一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834430/

相关文章:

json - 将 JSON 从模型传递到路由不起作用

javascript - 引用元素的 id

javascript - "Controllers polluting the Global Namespace"在Angular中是什么意思

javascript - 单击时切换灯箱中的可见区域。 Angular 和 JQuery

javascript - 我无法遵循 Node 初学者书中的以下代码片段

javascript - 如何获取客户端 Javascript 数组并通过 Node.js API POST 到 MongoDB 数据库?

javascript - jQuery 显示/隐藏面板,然后将鼠标悬停在面板内的内容上

javascript - 如何使用 jquery 前后循环遍历每个 li 或 div

javascript - 为什么我需要在 componentDidUpdate() 中使用 prevProps 和 prevState ?

AngularJS Flexslider 按钮和边距问题