0

I want to show data using 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 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:

    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?

1 Answer 1

1

Array.prototype.push.apply() can be used for merging two arrays.

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

<a ng-click="getPackageInfo(item.iCompanyID)">
Sign up to request clarification or add additional context in comments.

12 Comments

getPackageInfo(item.iCompanyID) this is not printing id
@hnn, You don't need to print it, You should define the function getPackageInfo in $scope object
but at first iCompanyID is not going to pass in here: <a ng-click="getPackageInfo(item.iCompanyID)">
it is displaying this: ng-click="getPackageInfo({id:item.iCompanyID})"
@hnn, It will pass when you click on the link, just do an alert and if its working as above the go with that
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.