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
1
vote
1 answer

Angularjs ng-if with ajax request

I'm new to angularjs and trying to figure out how to show/hide navbar elements depending on permissions. I'm currently getting the permissions via an ajax request: mycloudControllers.controller('HeaderController', ['$scope', '$http', …
1
vote
1 answer

ng-if showing empty DOM element when condition is not true

I have the following in a view file:

Sections:

KvnH
  • 496
  • 1
  • 9
  • 30
1
vote
1 answer

How to change text in this case using ng-if or other expression?

I'm trying to change the text in a title tag based on a tag's direction value:
  • Leon Gaban
    • 36,509
    • 115
    • 332
    • 529
  • 1
    vote
    1 answer

    angularjs ng-repeat inside ng-if

    angular js ng-if inside ng-repeat not working My angularjs ng-if code
    {{data.name}}
    Angu
    • 862
    • 2
    • 13
    • 32
    1
    vote
    1 answer

    do not include elements into ng-hide on form serialize

    I gotta a single question, I'm using ng-show and ng-hide to display options on a form based on a select option, however, when I submit my controller looks like this: app.controller("MyCtrl", function($scope) { $scope.submit = function(event) { …
    andresmijares
    • 3,658
    • 4
    • 34
    • 40
    1
    vote
    2 answers

    Why angularjs ignore ng-if?

    i try use ng-if, but angular no compile him. Look in test code:
    Citrael
    • 542
    • 4
    • 17
    0
    votes
    0 answers

    Problem with ng-if and angularjs how solution

    I have a problem between angularJS and select2 every time there is an ng-if select2 simply does not enable the search. I saw only one report of this fault but without solution.
    0
    votes
    2 answers

    ng-if or ng-repeat in angularjs remove web-components from DOM

    I have 14.2 angular and I need to reuse components from angular in the legacy project in angular js (1.8.3) using web components. I have two…
    0
    votes
    1 answer

    How to show and hide the calendar based on condition in angular

    I have an angular application in that I need to show the caledar based selected dropdown list. .component.ts OptionList: LookupActionCode[]=[]; public setList(actionType: any):void{ this.anotherOptionList = []; if(actionType ==…
    0
    votes
    0 answers

    AngularJs form validation not working with ng-show

    I am struggling with ng-show and $invalid logic, my requirement is very simple I need to make a form that will show input fields based on conditions. I need to add one datetime picker of moment.js. Issue starts when I understand that my datetime…
    0
    votes
    1 answer

    ng-keyup firing but not reading properly when used with an ng-if inside a directive template

    I have a directive and it works fine in a way such that when I type something the search() scope function inside my directive fires and sets $scope.query with the input text. here is the directive template
    cmgchess
    • 7,996
    • 37
    • 44
    • 62
    0
    votes
    0 answers

    If one element active then not show another one Angular JS

    I am working on AngularJS project. It's a store that has a search bar and profile, cart icon near it. When I click the search bar, it extends to the right and overlays the right icons. And when it happens, the number of items in a cart is still…
    NBash
    • 455
    • 3
    • 10
    0
    votes
    1 answer

    AngularJs UI Bootstrap dropdown position is miscalculated while adding ngif for dropdown-menu

    AngularJs UI Bootstrap is miscalculating position of dropdown while adding ng-if condition for ui element holding 'dropdown-menu' class. AngularJs UI Bootstrap version - 0.3.13 AngularJs version - 1.3.17 This is a plunker where issue is regenerated…
    Jeff Johny
    • 418
    • 1
    • 5
    • 19
    0
    votes
    3 answers

    Angularjs: Why does it execute function in ng-if when I click on table row?

    I have code on https://jsfiddle.net/8t45enfg/2/ The source code is quite simple, suppose the array list have only one element HTML code:
    0
    votes
    1 answer

    Using ng-if with directive take to much time [Slowly]

    I have a directive tree list view with checks box, (aleardy developed by another developer), i want to display it to the user when he clicks on button, so i used ng-if/ng-show/ng-hide/ng-class with hidden. they takes a lot of time to display the…
    Name Age