1

Inside my directive template i have this

<span sortable draggable></span>

Now i want to conditionally add sortable and draggale based on some scope variable

When i try this

<span ng-attr-sortable="false">

It basically becomes

<span sortable="false"></span> which still makes it sortable

I want sortable to be completely removed if expression is false

<span> </span>

1
  • If you can base your decisions on the attrs of your directive rather than the scope variables, then this solution might work to dynamically build your template: stackoverflow.com/a/20659860/1454888 Commented Feb 18, 2015 at 1:54

1 Answer 1

1

Should work with elem.removeAttr('sortable'). Where elem is the jQuery lite element, which you can pass in as link: function (scope, elem) { ... }, or using elem.find(...) to target a child element by tag name.

But that's something you may want to setup within your link: function () {...} as opposed to right in the template. You could always make your own filter for removing an attribute that you could then use within the template.

See: https://docs.angularjs.org/api/ng/function/angular.element (find removeAttr).

Sign up to request clarification or add additional context in comments.

4 Comments

that removeAttr is not working. MY template conatins another directive . is that can be the case because i have another dircetive inside that trmplate and i am trying to remove attribute from that directive
That works if i put inside compile function . If i put inside link function then it dont work. but in compile i don't have scope
@user3214546 Perhaps you need to recompile the element yourself and re-link it to the scope.
@demisx how can i do that , itried and it says compile function does not xist , any code??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.