How to append directives based on conditions

后端 未结 1 779
说谎
说谎 2021-01-27 15:34

I have 2 different directives. The first one is returns an iframe with a live video, and the second returns an iframe with a recent video.

The condition is: if live cont

相关标签:
1条回答
  • 2021-01-27 16:25

    Instead of handling the logic in the controller you can control it in UI as it will be easier.

    -----Other Html Codes-----
    <live-iframe ng-if="vm.live.items[0]" live="vm.live.items[0]"></live-iframe>
    <last-video ng-if="!vm.live.items[0]" video="vm.activity.items[0]"></last-video>
    -----Other Html Codes-----
    

    And you can remove following lines of code from the controller

    var liveIframe = '<live-iframe live="vm.live.items[0]"></live-iframe>';
    var videoIframe = '<last-video video="vm.activity.items[0]"></last-video>';
    
    if (vm.live.items[0] != undefined) {
        $('.iframe-container').append(liveIframe);
    } else {
        $('.iframe-container').append(videoIframe);
    }
    
    0 讨论(0)
提交回复
热议问题