What is the best way to conditionally apply attributes in AngularJS?

I need to be able to add for example “contenteditable” to elements, based on a boolean variable on 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 behavior? I’m considering writing a … Read more

How to set bootstrap navbar active class with Angular JS?

If I have a navbar in bootstrap with the items Home | About | Contact How do I set the active class for each menu item when they are active? That is, how can I set class=”active” when the angular route is at #/ for home #/about for the about page #/contact for the contact … Read more

How to access parent scope from within a custom directive *with own scope* in AngularJS?

I’m looking for any manner of accessing the “parent” scope within a directive. Any combination of scope, transclude, require, passing in variables (or the scope itself) from above, etc. I’m totally willing to bend over backwards, but I want to avoid something totally hacky or unmaintainable. For example, I know I could do it right … Read more

How to use a keypress event in AngularJS?

I want to catch the enter key press event on the textbox below. To make it more clear I am using a ng-repeat to populate the tbody. Here is the HTML: <td><input type=”number” id=”closeqty{{$index}}” class=”pagination-right closefield” data-ng-model=”closeqtymodel” data-ng-change=”change($index)” required placeholder=”{{item.closeMeasure}}” /></td> This is my module: angular.module(‘components’, [‘ngResource’]); I am using a resource to populate the … Read more

Angular directives – when and how to use compile, controller, pre-link and post-link [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 years ago. Improve this question When writing an Angular directive, one can use any of the following functions to manipulate the DOM behaviour, contents … Read more

What is the difference between ‘@’ and ‘=’ in directive scope in AngularJS?

I’ve read the AngularJS documentation on the topic carefully, and then fiddled around with a directive. Here’s the fiddle. And here are some relevant snippets: From the HTML: <pane bi-title=”title” title=”{{title}}”>{{text}}</pane> From the pane directive: scope: { biTitle: ‘=’, title: ‘@’, bar: ‘=’ }, There are several things I don’t get: Why do I have … Read more