angularjs - Toggling play / pause button using a directive in ionic / angular -


i want toggle play / pause button in ionic using directive, based on value of

$scope.autoplay 

in html have button element:

<playbtn></playbtn> 

the button ionic icon.

play button: <i class="ion-ios-play"></i>

pause button: <i class="ion-ios-pause"></i>

how should directive changed toggle icon ?

.directive('playbtn', function() {   return {     restrict: 'e',     template: '<i class=""></i>',     link: function(scope,element,attrs) {       if(scope.autoplay == 'true') {        //show pause button        } else {        //show play button       }     };       }  }) 

you can use ng-class so:

.directive('playbtn', function() {     return {       restrict: 'e',       scope: {autoplay:'='},       template: '<i ng-class="{\'ion-ios-play\': autoplay, \'ion-ios-pause\': !autoplay}"></i>'     } }) 

here's working fiddle.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -