【发布时间】:2016-02-20 10:50:52
【问题描述】:
我正在使用 MEANJS,其中 angularjs 是我的前端。我有我的文章列表,我带来了一个模态来编辑数据,但没有这样做并且模态不起作用。我正在为模态使用角度 UI 引导程序。我的fiddle。
HTML
<div ng-controller="MyCtrl">
<div ng-repeat="order in orders | limitTo:5">
<button class="btn btn-default" ng-click="open(order)">Edit {{ order.title }}</button>
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3>{{ order.title }}</h3>
</div>
<div class="modal-body">
<p ng-repeat="orde in order.orderfood">
{{orde.name}} {{orde.qty}} {{orde.price}}
</p>
</div>
</script>
</div>
</div>
JS
myApp.factory('Orders', ['$resource', function($resource) {
return $resource('https://safe-depths-4702.herokuapp.com/api/orders/:orderId', {
orderId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}]).controller('ModalInstanceCtrl', function($scope, $stateParams, $modalInstance, Orders) {
$scope.order = Orders.get({
orderId: $stateParams.orderId
});
$scope.ok = function(order) {
$modalInstance.close($scope.order);
};
}).controller('MyCtrl', ['$scope', '$uibModal', 'Orders', function($scope, $uibModal, Orders) {
$scope.orders = Orders.query();
$scope.name = 'Superhero';
$scope.open = function(size) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
order: function() {
return $scope.order;
}
}
});
};
}]);
我的fiddle。
【问题讨论】:
-
您的弹出窗口工作的原因是因为当您执行 ng-click() 时..您传递了一个参数 order... Order 未定义。
标签: angularjs angular-ui-bootstrap bootstrap-modal meanjs