编辑:我在这里重新创建了问题 http://plnkr.co/edit/w6yJ8KUvD3cgOrr56zH3?p=preview
我是 angularjs 新手,我正在尝试使用一些数据创建一个弹出模式..
我不明白为什么第一次打开它时它是空的,但第二次(等等)它很好。我所说的“好”是指标题就在那里。因此,每次重新加载页面时,第一次都是空的。
你能看到我错过了什么吗?
ModalController.js:
angular.module("Modal")
.controller("ModalController",
[
"$scope", "$uibModal", "$log", "ModalService", "AuthenticationService",
function($scope, $uibModal, $log, ModalService, AuthenticationService) {
AuthenticationService.GetCurrentWindowsUser(function(username) {
$scope.username = username;
});
$scope.openModal = function () {
AuthenticationService.GetItems($scope.username, function(items) {
$scope.items = items;
});
$scope.animationsEnabled = true;
$uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'modals/items.html',
controller: 'ModalInstanceController',
size: 'lg',
resolve: {
funds: function() {
return $scope.items;
}
}
});
};
}
])
.controller('ModalInstanceController', function($scope, $uibModalInstance, items) {
$scope.items = items;
$scope.ok = function() {
$uibModalInstance.close();
};
});
items.html:
<div class="container" ng-controller="ModalController">
<script type="text/ng-template" id="modals/items.html">
<div class="modal-header">
<h3 class="text-centered">items</h3>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ok()">SELECT</button>
</div>
</script>
</div>
首页.html:
<div class="container" ng-controller="ModalController">
<button type="button" class="btn btn-default" ng-click="openModal()">Large modal</button>
</div>
最佳答案
我设法通过删除我想要显示的模式中的脚本标签来解决这个问题
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<ul>
<li ng-repeat="item in items">
<a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
</li>
</ul>
Selected: <b>{{ selected.item }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
<button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
</div>
关于angularjs - 第一次加载时模态显示为空,第二次则不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34092276/