angularjs - angular directive exclude attribute if not set -


i trying create directive button - user require ng-click, , ui-sref

<md-button ng-click="controller.ngclick" ui-sref="controller.uisref"> 

obviously, 1 of these can set @ once - how can "hide" 1 that's not needed ?

if supply ng-click, need html like

<md-button ng-click="controller.ngclick"> 

and supply ui-sref, should like

<md-button ui-sref="controller.uisref"> 

is possible angular / directives ? or should create 2 directives, 1 of each type ?

i think simple solution - use additional "flag":

<md-button ng-click="controller.clickable ? controller.ngclick() : '';" ui-sref="!controller.clickable ? controller.uisref : '';"> 

or, using ng-if:

<md-button ng-if="controller.clickable" ng-click="controller.ngclick()"> <md-button ng-if="!controller.clickable" ui-sref="controller.uisref"> 

where controller.clickable - flag switch between click , href.


Comments