How can I get directive to fire after view loaded?

前端 未结 3 1693
眼角桃花
眼角桃花 2021-01-22 11:40

I know this has been asked a thousand time, but I think I\'ve tried every solution I\'ve read and I can\'t seem to get it to work.

I have an API from which I\'m getting

3条回答
  •  轮回少年
    2021-01-22 12:30

    I think this is happening because Angular is processing your directive before the results are bound to the list. It is probably a race condition. One way to solve this is to do

    $scope.$broadcast("picsDownloaded" ... 
    

    event in your controller after you get the results. On the directive, instead of

    scope.$watch(attr.photoswipe ....
    

    do this

    scope.$on("picsDownloaded" ....
    

    and in that handler you apply the Jquery Plugin.

提交回复
热议问题