如何在 node/express 路由中使用 angular-ui 模态模板 URL
how to use angular-ui modal templateURL with node/express routing
我对为什么会收到此错误感到有些困惑。我有一种预感,它与 templateURL 有关,我尝试了一些方法但无济于事。我已经阅读了文档并搜索了一堆 SO 帖子,但其中 none 帮助很大。我想使用 Express/Node 来提供页面,我感觉这就是为什么我的 templateURL 在 app.js.
中不起作用的原因
这是我的 index.html 以及我的控制器和模板。
<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,但这也会产生同样的错误。
这是错误跟踪:
使用 angular.js
而不是 angular.min.js
以获得更清晰的错误消息。
要解决此特定问题,您需要使用 ui-bootstrap-tpls.min.js
(或 ui-bootstrap-tpls.js
)而不是 ui-bootstrap.min.js
(ui-bootstrap.js
)。
在那之后,您可能还有一些其他问题,但也许那是一个不同的 SO 问题? :-)
我对为什么会收到此错误感到有些困惑。我有一种预感,它与 templateURL 有关,我尝试了一些方法但无济于事。我已经阅读了文档并搜索了一堆 SO 帖子,但其中 none 帮助很大。我想使用 Express/Node 来提供页面,我感觉这就是为什么我的 templateURL 在 app.js.
中不起作用的原因这是我的 index.html 以及我的控制器和模板。
<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,但这也会产生同样的错误。
这是错误跟踪:
使用 angular.js
而不是 angular.min.js
以获得更清晰的错误消息。
要解决此特定问题,您需要使用 ui-bootstrap-tpls.min.js
(或 ui-bootstrap-tpls.js
)而不是 ui-bootstrap.min.js
(ui-bootstrap.js
)。
在那之后,您可能还有一些其他问题,但也许那是一个不同的 SO 问题? :-)