Questions tagged [angular-ng-if]

'ngIf' is an Angular core directive that toggles the presence of the targeted element in the DOM. Do not use this tag for the 'ng-if' directive in the older AngularJS version.

ngIf is an Angular directive that alters the targeted element.

From the documentation:

Conditionally includes a template based on the value of an expression.

1223 questions
12
votes
2 answers

ngIf - else vs two ngIf conditions

Consider the following code sample:
Another way I can achieve the same…
Himanshu Arora
  • 2,368
  • 3
  • 22
  • 33
12
votes
3 answers

How to use ng-if with table to display td based on the condition

With reference to the earlier post on ng-if within DIV for reference the link given here :: Ng-If within DIV , however when i tried the same with ng-if inside table with ng-repeat on td it doesn't seems to work well. Correct me if I'm wrong I made 2…
Arun
  • 1,010
  • 6
  • 18
  • 37
11
votes
4 answers

Angular2 check if object has peoperty inside *ngIf

export interface Element { name: string; } export class Room implements Element { name: string; type:string } export class Hall implements Element { name: string; } and my varibale type is like below selectedElement: Element; now in…
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
11
votes
1 answer

Angular 2 ng2 How to use TypeScript enum inside template?

I have component for multiple filters with different types. For type recognition I want to use enum with filter types. How to use enum inside template when sample below does'nt work? I thought it should work by only importing enum inside component…
Adam Michalski
  • 1,722
  • 1
  • 17
  • 38
11
votes
1 answer

Selenium DOM is not changed after execution of Angular ng-if condition

we have following code on page which has angular ng-if condition.

Hi,

We have created a new account with ’{{ new_email }}‘, for you on
Plobal…

Sumit2500
  • 183
  • 7
11
votes
1 answer

Angular ng-show if string not empty does not work

I am writing a web app using AngularJS. The user submits up to 3 keywords to the server. I would like to show commas in between the keywords only if there are enough keywords. For example: if there are no keywords, then: if there is 1 keyword,…
11
votes
5 answers

ng-click not working with ng-if

Why does the second button not work, when ng-if is used? I want to realize a button that is present only when the model value is set / not ""/ not null. Template:
11
votes
1 answer

Applying ng-class based on value

I have a simple ng-repeat that displays a list of scores and a value of either Positive or Negative. What i am trying to do is when the value is Negative, display a red background CSS class, and when Positive, display a green CSS class. However, for…
11
votes
1 answer

Angular ng-if inside option element and ng-repeat not working

I have select element which should list available currencies. Default currency should have prefix "Default" before its name. For some reason, that prefix is showing for all currencies in the list. Test HTML:
NenadPavlov
  • 217
  • 1
  • 2
  • 10
10
votes
2 answers

How to set condition of a NaN value to show/hide a view using ngIf | angular 6

I want to hide a label when the value is NAN using *ngIf* but it's not working. The marked label is the default value of a variable, once the input is filled the value will be a number I want to show the label only when the value is not NAN What…
Ali
  • 1,633
  • 7
  • 35
  • 58
10
votes
4 answers

NgIf not updating when variable changes

Right, so i have a header component (navbar) which contains the following template:
  • Daanv z
    • 393
    • 1
    • 3
    • 16
  • 10
    votes
    3 answers

    checking string value in ng-if statement

    I would like to check the value of the property of an object and would like to check the data of string to compare.
    This text belongs in a table.
    So far all the divs appear with the text…
    bluePearl
    • 1,237
    • 4
    • 24
    • 42
    10
    votes
    2 answers

    Angular2: How do you run 2 animations in parallel?

    I have a container that expands/shrinks. There is an element inside that container that should fade in when the container expands and fade out when the container shrinks. My Problem When the container expands, the animation of both elements…
    AJ X.
    • 2,729
    • 1
    • 23
    • 33
    10
    votes
    3 answers

    *ngIf with focus directive

    In my app, I tried to place a button that shows/hides an input field with a boolean component property. If the button shows the input, focus should be set on the input. But it seems not to work. If I remove the *ngIf the focus directive works…
    Max Solid
    • 1,213
    • 3
    • 21
    • 32
    10
    votes
    4 answers

    Angular ng-if change span text

    I have this JSON file that I am taking objects as products from. When displaying the sizes of the products I want to change a span from "sizes:" to "kids:" when the json object has "kids": "1".
    user1780729
    • 520
    • 1
    • 7
    • 24
    1 2
    3
    81 82