All Questions
Tagged with angularjs-directiveangularjs
16,697 questions
1111votes
18answers
571kviews
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="...
774votes
33answers
653kviews
How to set focus on input field?
What is the 'Angular way' to set focus on input field in AngularJS? More specific requirements: When a Modal is opened, set focus on a predefined <input> inside this Modal. Every time <input&...
541votes
7answers
236kviews
When to favor ng-if vs. ng-show/ng-hide?
I understand that ng-show and ng-hide affect the class set on an element and that ng-if controls whether an element is rendered as part of the DOM. Are there guidelines on choosing ng-if over ng-...
536votes
6answers
244kviews
Link vs compile vs controller
When you create a directive, you can put code into the compiler, the link function or the controller. In the docs, they explain that: compile and link function are used in different phases of the ...
454votes
8answers
158kviews
Angular directives - when and how to use compile, controller, pre-link and post-link [closed]
When writing an Angular directive, one can use any of the following functions to manipulate the DOM behaviour, contents and look of the element on which the directive is declared: compile controller ...
428votes
19answers
516kviews
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{{$...
336votes
6answers
275kviews
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 ...
311votes
26answers
243kviews
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 ...
309votes
13answers
301kviews
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}}</...
300votes
13answers
339kviews
How to call a method defined in an AngularJS directive?
I have a directive, here is the code : .directive('map', function() { return { restrict: 'E', replace: true, template: '<div></div>', link: function($...
296votes
12answers
595kviews
AngularJS ng-style with a conditional expression
I am handling my issue like this: ng-style="{ width: getTheValue() }" But to avoid having this function on the controller side, I would much prefer to do something like this: ng-style="{ width: ...
285votes
3answers
95kviews
What is ng-transclude?
I have seen a number of questions on StackOverflow discussing ng-transclude, but none explaining in layman's terms what it is. The description in the documentation is as follows: Directive that ...
266votes
5answers
43kviews
When writing a directive in AngularJS, how do I decide if I need no new scope, a new child scope, or a new isolated scope?
I'm looking for some guidelines that one can use to help determine which type of scope to use when writing a new directive. Ideally, I'd like something similar to a flowchart that walks me through a ...
218votes
3answers
175kviews
Angular JS: What is the need of the directive’s link function when we already had directive’s controller with scope?
I need to perform some operations on scope and the template. It seems that I can do that in either the link function or the controller function (since both have access to the scope). When is it the ...
218votes
6answers
269kviews
How to set an iframe src attribute from a variable in AngularJS
I'm trying to set the src attribute of an iframe from a variable and I can't get it to work... The markup: <div class="col-xs-12" ng-controller="AppCtrl"> <ul class=""> <...