[英]ng-click show data in angular js
I want to show data using ng-click
我想使用
ng-click
显示数据
First i have listing for of all the companies, this works fine. 首先,我有所有公司的清单,这很好。 it displays all the companies.:
它显示所有公司。
<div class="col-xs-3" ng-repeat="item in companyData">
<a ng-click="getPackageInfo({id:item.iCompanyID})" class="block panel padder-v bg-primary item">
<span class="text-white block">{{item.vCompanyName}}</span>
</a>
</div>
Now on click of company name, i have to display other info like packges of that company, for that i have done this under above div
: 现在单击公司名称,我必须显示其他信息,例如该公司的包装,为此,我已经在
div
以上进行了此操作:
<div ng-repeat="item in pData" class="col-xs-3">
<a ng-click="" class="block panel padder-v bg-primary item">
<span class="text-white block">{{item.vPackageName}}</span>
</a>
</div>
In controller.js
i did this, getPackageInDetail will return package listing according to company id: 在
controller.js
我这样做了, getPackageInDetail将根据公司ID返回包裹清单:
function getPackageInfo(id) {
SubscriptionoptioncompanylistFactory.getPackageInDetail(id).
success(function(data) {
$scope.pData = data;
}).
error(function(data,status,header,config) {
$scope.pData = 0;
});
};
How can i append the data according to company clicked? 如何根据所点击的公司附加数据?
Array.prototype.push.apply()
can be used for merging two arrays. Array.prototype.push.apply()
可用于合并两个数组。
Merge the second array into the first one
将第二个数组合并到第一个数组中
//Define an empty array
$scope.pData = [];
$scope.getPackageInfo = function(id) {
SubscriptionoptioncompanylistFactory.getPackageInDetail(id).
success(function(data) {
Array.prototype.push.apply($scope.pData, data); //Merge the array
});
};
Additionally, I think you need to pass ID properly 另外,我认为您需要正确传递ID
<a ng-click="getPackageInfo(item.iCompanyID)">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.