Questions tagged [angularjs-ng-if]

The AngularJS ngIf directive removes or recreates a portion of the DOM tree based on an {expression}. If the expression assigned to ngIf evaluates to a false value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.

ngIf differs from ngShow and ngHide, as ngIf completely removes and recreates the element in the DOM rather than changing its visibility via the display css property. A common case when this difference is significant is when using css selectors that rely on an element's position within the DOM, such as the :first-child or :last-child pseudo-classes.

Note that when an element is removed using ngIf, its scope is destroyed and a new scope is created when the element is restored. The scope created within ngIf inherits from its parent scope using prototypal inheritance. An important implication of this is if ngModel is used within ngIf to bind to a javascript primitive defined in the parent scope. In this case any modifications made to the variable within the child scope will override (hide) the value in the parent scope.

Also, ngIf recreates elements using their compiled state. An example of this behavior is if an element's class attribute is directly modified after it's compiled, using something like jQuery's .addClass() method, and the element is later removed. When ngIf recreates the element the added class will be lost because the original compiled state is used to regenerate the element.

Additionally, you can provide animations via the ngAnimate module to animate the enter and leave effects.

ngIf docs

92 questions
0
votes
1 answer

How to show a element for each rows clicked in angularjs

I just want to make the marked and unmarked icon of each below appear based on the response from the server. I've read series of relevant questions but all seems to be ng-class related, I tried to apply them too but they seem not to be working, I'm…
0
votes
1 answer

ng-if does not work when placed outside of controller and $compile-ed with scope, but ng-show does

I have a plain angular application which adds variables to the scope and simply display them. Which is simple and working. But there is a part of the page that does not run in angular (practically it is a jQuery plugin), so I have to use $compile to…
0
votes
1 answer

Skip duplicated items while ng-repeat

There is a nested array which consist of bundles and those bundles in turn have items. So, I want to skip identical item(s) of the next bundle based on previous bundle items while iterating. Below is data model and code snippets: vm.data [ { …
0
votes
0 answers

Add font-awesome icon to one option in select created by an ng-repeat

Is it possible to add an icon to an option in a dropdown based on if it matches a certain setting from the data returned in an ng-repeat? I have the following select and the options within that select are created via an ng-repeat that is going off…
0
votes
1 answer

AngularJs 1.x not updating the visibility of element with ng-show or ng-if either

I am facing issue with the angular js 1.x not updating the visibility of the element even when variable values are detected. I am using custom angular open-close symbols but I don't see this as an issue. Here's the sample code:
  • 0
    votes
    1 answer

    Bootstrap tooltip : hide tooltip if binding variable value is null

    I'm working with angularJS and haml syntax and I want to hide the tooltip on mouse hover if an attribute is null, this the line that show it : %td %a{ ng_href: '/reports/{{decoratedReport.id}}/download'} …
    user9569059
    0
    votes
    1 answer

    Correct use of ng-if directive in html

    I've following html code snippet where I would like to use some "ng-*" directive to conditionally apply color to the text. 1
    2
    0
    votes
    1 answer

    AngularJS ng-hide/show label/button if length(description) < 20

    I need to show/hide label if length(description) < one row. Code is working ok, but if length < one row, label isn't hide. How to hide/show label? If [[ demandAd.description ]] less than one line or less than one row(or length < 100), I need to hide…
    0
    votes
    2 answers

    Angular ng-repeat with ng-if not working on tr tag

    In the below Div i am using ng-repeat across some data to populate a list. while doing this i would like to NOT have a a certain TR tag created if it fits a certain requirement by using the ng-if directive on x.Equipment_Cost_Child != 0 However…
    0
    votes
    0 answers

    Angularjs : add multiple ng_if condition in with haml syntax

    I'm working on an item_selector directive, I want to add an indicator for archived element, this is the item selector template .haml : .directive-items-selector{ ng_click: "openItemsSelector( $event )" } .wrapper %ui_select.ui-select{ ng: {…
    user9569059
    0
    votes
    0 answers

    Allowing multiple directives to transclude in a recursive template

    I am currently receiving a tree of managers and their subordinates from the back end. I'm using a recursive template to display this.