2012-10-05 40 views
1

定制指令$表评估我有一个低于angularjs定制指令,它使用模型这就是会从服务器上更新, 我添加了一个手表听众观看该模型的变化,表达式在angularjs

var linkFn; 
linkFn = function(scope, element, attrs) { 
     scope.$watch('$parent.photogallery', function(newValue, oldValue) { 
      if(angular.isUndefined(newValue)) { 
      return; 
     } 
     var $container = element; 
     alert($container.element); 
     $container.imagesLoaded(function() { 
      $container.masonry({ 
      itemSelector : '.box' 
       }); 
      }); 
     }); 
    }; 
    return { 
     templateUrl:'templates/Photos_Masonry.htm', 
     replace: false, 
     transclude:true, 
     scope: { 
      photogallery: '=photoGallery', 
     }, 
     restrict: 'A', 
     link: linkFn 

但是,当我在我的watch指令中调试时,我仍然看到模板中的表达式仍然无法解析.ie photo.label,ng-src都还没有解决。 AFIK,只有$ eval后才会调用$ digest。这是预期的行为? 由于这个,我的jQuery调用不工作?有没有其他事件,我得到结果元素与评估表达式?

这里是我的模板,这NG-重复它,

<div id="container" class="clearfix"> 
    <div class="box col2" ng-repeat="photo in photogallery"> 
     <a ng-href="#/viewphotos?id={{photo.uniqueid}}&&galleryid={{galleryid}}" 
      title="{{photo.label}}"><img 
      ng-src="{{photo.thumbnail_url}}" alt="Stanley" class="fade_spot" /></a> 
     <h3> 
      <span style="border-bottom: 1px solid black;font-weight:normal;font-size:14px;">{{galleryname}}</span> 
     </h3> 
     <h3> 
      <span style="color:#20ACB8;font-weight:normal;font-size:17px;">{{photo.seasonname}}</span> 
     </h3> 
    </div> 
</div> 

照相馆在父控制器初始化,

function MyCtrlCampaign($scope, srvgallery, mygallery) { 

    $scope.updatedata = function() { 
     $scope.photogallery  = srvgallery.getphotos($routeParams); 
    }; 

    $scope.getphotos = function() { 
     srvgallery.photos().success(function(data) { 
      $scope.updatedata(); 
     }).error(function(data) { 

     }); 
    }; 

指令在下面的方式使用,

<div masonry photo-gallery="photogallery" > 
      </div> 

请让我知道你对此的看法。

+0

我不清楚在哪里照相馆初始化 –

+0

嗨罗伊,照片库初始化在父控制器。 –

+0

Roy,也更新了这些细节的问题。 –

回答

0

看起来像这个问题已经在您的Github issue(为方便他人发布)解决。