2014-09-05 162 views
0

我有板球选手卡,其中用户可以选择11出30可能,有2在测试atm,问题是,我选择在一个孩子的球员它将它们添加到父范围中声明的数组中。然后,相同的数组映射到不同的子范围,但值不会传递。代码下面,任何帮助将是伟大的。干杯!!孩子范围到家长范围不同的孩子范围

var page = '<div class="section cricket">' + 

'<div class="input-frame " focus-after-error fill-panel>' + 

'<p>Your Choices</p>' + 

'<div class="chosen-cards" data-cards-chosen="chosenPlayers" data-chosen-cards>' + 

'</div>' + 

'</div>' + 

'<div class="input-frame" focus-after-error fill-panel>' + 

'<fieldset class="cricket-inputs" id="custom-checkbox" data-error-message="There is an error" data-required="true" data-cards="" data-player-cards="players">' + 

'</fieldset>' + 

'</div>' + 

'</div>'; 

var card = '<div class="card" ng-repeat="playerCard in playerCards" data-choose-card="" data-name=" {{playerCard.name}}" data-img="{{playerCard.img}}">' + 

'<div class="player" >' + 

'<img src="images/{{playerCard.img}}">' + 

'<div class="inner-overlay"></div>' + 

'</div>' + 

'<p>{{playerCard.name}}</p>' + 

'</div>'; 

(function() { 
'use strict'; 

// -------------------------------------------------------------------------- 
// Cricket Page 
// -------------------------------------------------------------------------- 

angular.module('eform').directive('cricket', ['$timeout', function ($timeout) { 

    return { 
     restrict: 'A', 
     template: page, 
     scope: true, 
     controller: function($scope){ 



     }, 
     link: function($scope, $element){ 

      $scope.players = [ 
       {name: 'George Baily', img: 'Bailey.png'}, 
       {name: 'Micheal Clarke', img: 'Clarke.png'} 
      ]; 

      $scope.chosenPlayers = []; 

      $timeout(function(){ 

       $element = $element.find('.card'); 

       $element.on('click', function(){ 

        var $this = $(this); 

        if($this.hasClass('chosen')){ 

         $this.removeClass('chosen').removeClass('active'); 

        } else { 

         $this.addClass('chosen'); 

         $scope.chosenPlayers.push({name : $this.attr('data-name'), img : $this.attr('data-img')}); 

        } 

       }); 

       $($element[0]).hover(function() { 

        var $this = $(this); 

        $this.addClass('active'); 

       }, function() { 

        var $this = $(this); 

        $this.removeClass('active'); 

       }); 


      }); 

     } 

    }; 

}]); 

})(); 

(function() { 
'use strict'; 

// -------------------------------------------------------------------------- 
// Cricket card 
// -------------------------------------------------------------------------- 

angular.module('eform').directive('cards', [ function() { 

    return { 
     restrict: 'A', 
     template: card, 
     scope : { 
      playerCards : '=playerCards' 
     } 
    }; 

}]); 

})(); 


(function() { 
'use strict'; 

// -------------------------------------------------------------------------- 
// Cricket card 
// -------------------------------------------------------------------------- 

angular.module('eform').directive('chosenCards', [ function() { 

    return { 
     restrict: 'A', 
     template: card, 
     scope : { 
      playerCards : '=cardsChosen' 
     } 
    }; 

}]); 

})(); 

回答

0

干杯每个人都帮忙。原来我需要

$ scope.apply()后,我把值推入数组。

社区再次真的有帮助。