I have a directive to show/hide element based on something. But it doesn't work where element have binding to some value. I want my directive still working in this condition.
angular.module("app", [])
.controller('ctrl', function ($scope){
$scope.color = "red";
})
.directive('xred', function() {
return {
link: function(scope, element, attrs) {
var role = 0;
if (role === 0) element.css('display', 'none');
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<!-- where I hard code 'blue', xred directive is working-->
<span xred style="color: blue"> Blue (should hide) </span>
<!-- where I bind color, xred directive is not working.-->
<span xred style="color: {{color}}"> Red (should hide) </span>
</div>