[英]Pass argument to $http get through Angular UI Modal
I have a list of details, when a user clicks an icon I want it to open a modal that pulls more data on that specific facet. 我有一个详细信息列表,当用户单击一个图标时,我希望它打开一个模式,该模式可以在该特定方面上提取更多数据。 I'm using Angular UI's Bootstrap Directives. 我正在使用Angular UI的Bootstrap指令。
My current controller looks like this 我当前的控制器看起来像这样
controller('orderCtrl', function($scope, $modal, $http){
var orderModalCtrl = function ($scope, $modalInstance, $http, orders){
$http.get('json/SI1.json').success(function(data){
$scope.orders = data;
});
};
$http.get('json/current.json').success(function(data){
$scope.topLevelOverview = data;
});
$scope.open = function() {
$('body').css('overflow', 'hidden');
var modalInstance = $modal.open({
templateUrl: 'template/modal/orderModal.html',
windowClass: 'contactModal',
controller: orderModalCtrl,
backdrop : 'static',
resolve:{
orders: function (){
return $scope.orders;
}
}
});
modalInstance.result.then(function (){
$('body').css('overflow', 'scroll');
}, function(){
$('body').css('overflow', 'scroll');
});
};
});
The modal is opened from a button in an ng repeat. 从ng重复按钮中打开模态。 That looks similar to this: 看起来类似于:
<div ng-repeat="(key,overview) in order.orderDetails">
<div class="row" ng-repeat="(key, val) in overview.snippet">
<div class="span2"><p>{{val.item1}}</p></div>
<div class="span3"><p>{{val.item2}}</p></div>
<div class="span3"><p>{{val.qty}}</p></div>
<div class="span3"><p>{{val.freq | capitalize}}</p></div>
<div class="span1"><a href="" class="btn button" ng-click="open();">
<i class="fa fa-file-text fa-2x"></i></a></div>
</div>
</div>
I want to pass an argument that changes what the GET request is based on which item the user clicks, 101, 102, 103 etc. I think something like this might work: 我想传递一个参数,该参数根据用户单击的项目101、102、103等来更改GET请求的内容。我认为这样可能有效:
<div class="span1"><a href="" class="btn button" ng-click="open(); routeTo({{val.item1}});">
<i class="fa fa-file-text fa-2x"></i></a></div>
From the earlier controller: 从早期的控制器:
var orderModalCtrl = function ($scope, $modalInstance, $http, orders){
$scope.routeTo = function(route){
$http.get('json/'+route+'.json').success(function(data){
$scope.orders = data;
});
};
};
I believe this would work however there has to be a better way. 我相信这会奏效,但是必须有更好的方法。 I've done my best to Google and read through the documentation for $http and Angular UI. 我已经尽力向Google并阅读$ http和Angular UI的文档。
I use dialogService from old angularUI and it is probably similar because dialogService was developed to modalService and it now contains functions from. 我使用旧的angularUI的dialogService,这可能是相似的,因为dialogService已开发为modalService,并且现在包含来自的函数。 Try this: 尝试这个:
open
function: <a href="" class="btn button" ng-click="open(val.item1);">
将项目ID传递给open
功能: <a href="" class="btn button" ng-click="open(val.item1);">
open
function: $scope.open = function(item) { ... }
修改open
函数: $scope.open = function(item) { ... }
$modal.open
, for example item: item
只需将下一个属性添加到传递给$modal.open
对象,例如item: item
var myItem = dialog.options.item;
在由dialogService创建的控制器中,我是通过这种方式获得的: var myItem = dialog.options.item;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.