angular-ng-if

Angular 4 default radio button checked by default

你离开我真会死。 提交于 2019-11-27 20:29:48
I'm trying to mark as a default a radiobutton depending on the value I get from my object, it can be True or False. What could I do to mark as a default radiobutton depending on the option? <label>This rule is true if:</label> <label class="form-check-inline"> <input class="form-check-input" type="radio" name="mode" value="true" [(ngModel)]="rule.mode"> all of the following conditions are true </label> <label class="form-check-inline"> <input class="form-check-input" type="radio" name="mode" value="false" [(ngModel)]="rule.mode"> at least one of the following conditions is true </label> I have

How to conditionally wrap a div around ng-content

99封情书 提交于 2019-11-27 18:45:13
depending on the value of a (boolean) class variable I would like my ng-content to either be wrapped in a div or to not be wrapped in div (I.e. the div should not even be in the DOM) ... Whats the best way to go about this ? I have a Plunker that tries to do this, in what I assumed was the most obvious way, using ngIf .. but it's not working... It displays content only for one of the boolean values but not the other kindly assist Thank you! http://plnkr.co/edit/omqLK0mKUIzqkkR3lQh8 @Component({ selector: 'my-component', template: ` <div *ngIf="insideRedDiv" style="display: inline; border: 1px

Angular - Changing scope is not getting reflected

血红的双手。 提交于 2019-11-27 16:24:18
This is weird as it should be pretty straightforward. I will post my code first and then ask the question: html - <div ng-controller="myController" ng-switch on="addressCards"> <div> {{addCustom}} // does not get changed <div ng-if="addCustom === false"> {{addCustom}} // does get changed <button type="button" class="btn btn-primary btn-icon-text" ng-click="addCustom = true"> <span class="icon icon-plus"></span> click here </button> </div> </div> </div> controller - (function(){ 'use strict'; angular.module('myApp') .controller('myController',['$scope',myController]); function myController(

Passing ngFor variable to an ngIf template

强颜欢笑 提交于 2019-11-27 06:42:56
问题 How do I pass the current variable in an ngFor loop to ngIf, if it is using templates with then/else syntax? It appears that they pass through fine when used inline, but aren't accessible from a template, for example: <ul *ngFor="let number of numbers"> <ng-container *ngIf="number % 2 == 0; then even_tpl; else odd_tpl"><>/ng-container> </ul> <ng-template #odd_tpl> <li>Odd: {{number}}</li> </ng-template> <ng-template #even_tpl> <li>Even: {{number}}</li> </ng-template> The templates don't seem

How to show 1 element in ngFor in angular2?

时光毁灭记忆、已成空白 提交于 2019-11-27 04:44: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

AngularJS ng-if and scopes [duplicate]

人盡茶涼 提交于 2019-11-27 01:50:44
问题 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

AngularJS watch DOM change

纵然是瞬间 提交于 2019-11-27 01:17:34
I have one auto-carousel directive which iterates through the linked element's children . The children however are not yet loaded in the DOM, because their ng-if s expressions have not been parsed yet. How can I make sure the parent directive knows there have been changes to it's DOM tree? <ul class="unstyled" auto-carousel> <li class="slide" ng-if="name">{{name}}</li> ... <li class="slide" ng-if="email">{{email}}</li> </ul> I could use $timeout but that feels unreliable. I could also use ng-show instead of ng-if but that does not answer the question and not what I need. So here's what I ended

Angular 4 default radio button checked by default

痞子三分冷 提交于 2019-11-26 20:08:21
问题 I'm trying to mark as a default a radiobutton depending on the value I get from my object, it can be True or False. What could I do to mark as a default radiobutton depending on the option? <label>This rule is true if:</label> <label class="form-check-inline"> <input class="form-check-input" type="radio" name="mode" value="true" [(ngModel)]="rule.mode"> all of the following conditions are true </label> <label class="form-check-inline"> <input class="form-check-input" type="radio" name="mode"

AngularJS watch DOM change

雨燕双飞 提交于 2019-11-26 09:39:29
问题 I have one auto-carousel directive which iterates through the linked element\'s children . The children however are not yet loaded in the DOM, because their ng-if s expressions have not been parsed yet. How can I make sure the parent directive knows there have been changes to it\'s DOM tree? <ul class=\"unstyled\" auto-carousel> <li class=\"slide\" ng-if=\"name\">{{name}}</li> ... <li class=\"slide\" ng-if=\"email\">{{email}}</li> </ul> I could use $timeout but that feels unreliable. I could

*ngIf and *ngFor on same element causing error

老子叫甜甜 提交于 2019-11-25 22:06:15
问题 I\'m having a problem with trying to use Angular\'s *ngFor and *ngIf on the same element. When trying to loop through the collection in the *ngFor , the collection is seen as null and consequently fails when trying to access its properties in the template. @Component({ selector: \'shell\', template: ` <h3>Shell</h3><button (click)=\"toggle()\">Toggle!</button> <div *ngIf=\"show\" *ngFor=\"let thing of stuff\"> {{log(thing)}} <span>{{thing.name}}</span> </div> ` }) export class ShellComponent