angular-ng-if

*ngIf else if in template

二次信任 提交于 2019-11-29 20:50:16
How would I have multiple cases in an *ngIf statement? I'm used to Vue or Angular 1 with having an if , else if , and else , but it seems like Angular 4 only has a true ( if ) and false ( else ) condition. According to the documentation, I can only do: <ng-container *ngIf="foo === 1; then first else second"></ng-container> <ng-template #first>First</ng-template> <ng-template #second>Second</ng-template> <ng-template #third>Third</ng-template> But I want to have multiple conditions (something like): <ng-container *ngIf="foo === 1; then first; foo === 2; then second else third"></ng-container>

Focus an element after it appears via ngIf

两盒软妹~` 提交于 2019-11-29 17:36:35
I have a button that, when clicked, is replaced with an input field and a confirmation button, then when input is finished it's replaced with the original button again. When that happens, I want it to focus the original button after it appears (some users have requested better support for tab-navigation), but I can't seem to get it to do that consistently. The best I've been able to do is this: // component.html <button #durationButton *ngIf="!enteringDuration" (click)="enterDuration()">Enter Duration</button> <ng-container *ngIf="enteringDuration"> <input type="number" [(ngModel)]="duration"

angular2 toggle icons inside ngFor [duplicate]

只谈情不闲聊 提交于 2019-11-29 11:02:01
This question already has an answer here: Hide/show individual items inside ngFor 5 answers Can some one please let me know how to toggle icons while doing ngFor? Problem Statement: I'm using *ngFor to loop through an array and display category names. On click of day I need to open an accordian and show category details (I can do this). Once accordian opens I need to replace fa-plus icon with fa-minus and vice-versa and I need to do this only for clicked day. How can I achieve this effectively? this.categoryList = [ {type: 'space', name: 'Space'}, {type: 'energy', name: 'Energy'}, {type:

Event to fire when an angular *ngIf statement evaluates in template

房东的猫 提交于 2019-11-29 09:35:07
If I have the following: <div *ngIf="user$ | async as user" class="container"> <p>user.name</p> </div> Is there a way I can execute code when the div above finally appears on screen? The ngIf will remove that DOM element and all attached components/directives. So you can just write a simple directive that executes an event when it's first created. When the ngIf transitions from false to true the directive will be created (again, and again, etc...) @Directive({selector: '[after-if]'}) export class AfterIfDirective implements AfterContentInit { @Output('after-if') public after: EventEmitter

Applying ng-class based on value

China☆狼群 提交于 2019-11-29 03:54:05
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 some reason, i am always seeing the red CSS class on my page. HTML: <tr ng-repeat="scores in Test" ng-class="{true: 'warning', false: 'ok'}[scores.Indicator == 'Negative']"> <td>Overall: {{ scores.Indicator }}</td> </tr> CSS: .warning { background: red; } .ok { background: green; } I haven't seen that particular syntax used before, what's the

*ngIf else if in template

和自甴很熟 提交于 2019-11-28 15:54:36
问题 How would I have multiple cases in an *ngIf statement? I'm used to Vue or Angular 1 with having an if , else if , and else , but it seems like Angular 4 only has a true ( if ) and false ( else ) condition. According to the documentation, I can only do: <ng-container *ngIf="foo === 1; then first else second"></ng-container> <ng-template #first>First</ng-template> <ng-template #second>Second</ng-template> <ng-template #third>Third</ng-template> But I want to have multiple conditions (something

AngularJS ng-if and scopes [duplicate]

岁酱吖の 提交于 2019-11-28 07:32:17
This question already has an answer here: What are the nuances of scope prototypal / prototypical inheritance in AngularJS? 3 answers I am trying to understand ng-if and scopes. As I am aware, ng-if creates a new child scope. Here is my issue: View <input ng-model="someValue1" /> <div ng-if="!someCondition"> <input ng-model="$parent.someValue2" /> </div> Controller $scope.someCondition = true; if ($scope.someCondition) { $scope.someValue2 = $scope.someValue1; } If someCondition is set to true, then someValue2 should be the same as someValue1. My problem is that I can't access someValue2 in

angular2 toggle icons inside ngFor [duplicate]

泄露秘密 提交于 2019-11-28 03:55:46
问题 This question already has answers here : Hide/show individual items inside ngFor (5 answers) Closed 2 years ago . Can some one please let me know how to toggle icons while doing ngFor? Problem Statement: I'm using *ngFor to loop through an array and display category names. On click of day I need to open an accordian and show category details (I can do this). Once accordian opens I need to replace fa-plus icon with fa-minus and vice-versa and I need to do this only for clicked day. How can I

Event to fire when an angular *ngIf statement evaluates in template

家住魔仙堡 提交于 2019-11-28 02:53:40
问题 If I have the following: <div *ngIf="user$ | async as user" class="container"> <p>user.name</p> </div> Is there a way I can execute code when the div above finally appears on screen? 回答1: The ngIf will remove that DOM element and all attached components/directives. So you can just write a simple directive that executes an event when it's first created. When the ngIf transitions from false to true the directive will be created (again, and again, etc...) @Directive({selector: '[after-if]'})

How to show 1 element in ngFor in angular2?

◇◆丶佛笑我妖孽 提交于 2019-11-28 00:32:01
I have a simple ngFor that loops through an array. However, I've added a condition that while the index is < 5 keep add the tag. and After that, I want to add an extra tag just once that will be used a dropdown to view the rest of the tags. But it doesn't work. <li *ngFor="let tag of module.Tags; let i = index"> <a *ngIf="i<5" href="#" class="span-tag tag">{{ tag }}</a> <div *ngIf="module.Tags.length > 5 && i == 6">DropDown Button</div> </li> The feature here is that I don't want to show unlimited number of tags to the user, I want to limit it to only 5 tags, and have a button after 5 tags