samedi 9 mai 2015

very starnge behaviour with for loop and data-ng-init()

     I was trying to pass array of ids from controller to custom directive and in custom directive i need to get the whole object from server using some api and need to display it using ng-repeat. but when page gets loaded it should display, should not use any click events and all. 

here is my controller.

   $scope.$on('itemSelectedEvent', function (event, args) {
    $scope.selectedId = args.selectedId;
     $scope.searchId = args.searchId;
     $scope.searchType = args.searchType;
     getOrg($scope.selectedId).fetch({'searchType': $scope.searchType}).$promise.then(
              function (value) {
    switch($scope.data.searchType)

    {
    case 'tei_org' :
    $scope.recipientsOrgIdArr.push(data.relatedEntityInstanceId);

//need to pass this array of ids to directive
    break;
                 case 'tei_person' :
    $scope.recipientsPeopleIdArr.push(data.relatedEntityInstanceId);
//need to pass this array of ids to directive

      break;
                        }
    })
    });

my html file...

<search  searchobj="tei_org"  selecteditemslist="recipientsOrgIdArr"   searchid="organisation" />

sending array of ids (recipientsOrgIdArr) to the directive like this .

my directive html

{{list}}x

display(selecteditemslist,searchid,searchobj) function should get call when page is loaded

display() contains

  $scope.display = function (list, searchid, searchobj) {
    for (var i = 0; i < list.length; i++) {
            getOrg(list[i]).fetch({
                'searchType': searchobj
            }).$promise.then(
                function (value) {
    var data = {
                        'id': $scope.displayItem.id,

                        'item': $scope.displayItem.displayConfig[0].propertyValue
                    };
                    $scope.item.push(data.item);
    });
    }
    }

i had strucked with three problems.... 1) i dont know whats going wrong data-ng-init() was not getting call

2) my for loop is repeating twice of the length, i.e if length is 2 it was looping 4 times and iam getting duplicate items while displaying.

3) last thing is while displaying previous items aslo getting displayed but my requirment is they have to become null only current items should display.

please friends help me to solve this problem

Aucun commentaire:

Enregistrer un commentaire