Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I need to be able to add for example "content editable" to elements, based on a boolean variable on a scope.

Example use:

<h1 attrs="{'contenteditable=\"true\"': editMode}">{{content.title}}</h1>

Would result in contenteditable=true being added to the element if $scope.editMode was set to true. Is there some easy way to implement this ng-class like attribute behaviour? I'm considering writing a directive and sharing if not.

1 Answer

0 votes
by (106k points)

The best way to conditionally apply attributes in AngularJS you need to set the class attracts when ng-class can't be used:-

ng-attr-class="{{someBoolean && 'class-when-true' || 'class-when-false' }}"

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...