angular-ng-if

Model does not update within ng-if

雨燕双飞 提交于 2019-12-05 01:03:54
I've got a strange behavior in an angular application and I don't know if that's a bug or a known limitation: 'use strict'; var ctrl = function ($scope) { $scope.foo = false; }; <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app ng-controller="ctrl"> foo: {{foo}} <div ng-if="foo" style="background-color: #f00;"> <p>foo</p> </div> <div ng-if="!foo"> <br/><button ng-click="foo = true;">Show foo</button> </div> <button ng-click="foo = true">Show foo</button> </div> http://jsfiddle.net/78R52/ I would expect that clicking one of the buttons

AngularJs ng-if comparing dates

做~自己de王妃 提交于 2019-12-04 23:57:44
I am looking to compare two dates in ng-if this is what my jade file looks like. li.list-group-item(ng-if="app.Segments[0].StartDate.getTime() > date.getTime()") div.row div.col-xs-12 span i.fa.fa-plus-square This code will hopefully add an li to my ui if the startdate of the first segment is after today. $scope.date = new Date(); $scope.app = { Segments: [{ StartDate: 2014-11-15T04:00:00.000Z EndDate: 2014-11-20T04:00:00.000Z }, { StartDate: 2014-11-21T04:00:00.000Z EndDate: 2014-11-25T04:00:00.000Z }] } Is there anyway to make this work? If they're date object just compare them directly

Angularjs: how to close ng-if in comment block?

安稳与你 提交于 2019-12-04 23:45:59
<div ng-if="true">visible</div> is pretty easy, but since ngIf can be used even in comments, what would be the closing </div> for comment block? Tried, w/o luck: <!-- ng-if: true --> .... <!-- ng-if --> Thanks. ng-if is restricted to 'A' . so it can be used only as attribute, you can't use in comment Here's the angularjs code for ngIf var ngIfDirective = ['$animate', function($animate) { return { transclude: 'element', priority: 600, terminal: true, restrict: 'A', // --> This means restricting to Attribute The restrict option is typically set to: 'E' , 'A' , 'C' , 'M' One of EACM restricts the

Angular-slick ng-repeat $http get

蓝咒 提交于 2019-12-04 20:53:08
问题 I've been trying all the week end to display data (that I fetch with $http.get ) in the slick angular carousel using ng-repeat , in vain... I've read about the well known issue: here and here. I tried to use the init-onload and data attributes, in vain... HTML: <div ng-controller="LandingCtrl as ctrl"> ... <slick init-onload=true data="ctrl.products"> <div ng-repeat="product in ctrl.products"><img src="{{product.image}}" alt="{{product.title}}"></div> </slick> ... </div> JS : angular.module(

Content briefly rendering then disappearing using ng-if

倖福魔咒の 提交于 2019-12-04 09:47:49
I have some content on my page which is wrapped in an ng-if like below: <div ng-if="ShowMessgae" class="text-danger"> <p> <strong> Message displayed to User </strong> </p> </div> Then in my angular js controller I have the following: function MyController($scope, $q, notifyHelper) { openAjaxLoaderGif(); $scope.ShowMessgae = false; MyService.getVarsFromSession().then(function (result) { // some code removed for brevity if(some coditional) { $scope.ShowMessgae = true; } }, function (data, failReason, headers) { notifyHelper.error("Error has occurred - try again"); }) }) .finally(function () {

How to display Yes/No instead of True/False in AngularJS [closed]

人走茶凉 提交于 2019-12-04 01:52:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am using the cellTemplate to display the data in grid ,now i have to display the data in ng-grid ,where i can display the data containing true or false value in one column ,please guide me how to display the true or false data like yes or no ,i.e ,for true value i have to display yes and for false value to no

Angular 2- using *ngIf with multiple conditions

霸气de小男生 提交于 2019-12-03 23:36:13
I'm unable to selectively display links on my nav-bar. Based on who logs in (user or admin), I want to change which link shows on my nav-bar. Below is the code for one such instance where the user/admin logs out. In navbar.component.html - <li *ngIf="authService.userLoggedIn()== true && authService.adminLoggedIn() == false" [routerLinkActive]="['active']" [routerLinkActiveOptions]="{exact:true}"> <a (click)="onUserLogoutClick()" href="#">Logout</a> </li> <li *ngIf="(authService.adminLoggedIn() == true) && (authService.userLoggedIn() == false)" [routerLinkActive]="['active']"

Focus an element after it appears via ngIf

落爺英雄遲暮 提交于 2019-12-03 18:14:11
问题 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

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

天大地大妈咪最大 提交于 2019-12-03 11:51:13
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: <div ng-app="testApp"> <div ng-controller="MainCtrl"> <select> <option ng-repeat="rate in rates track by $index"> <span ng-if="rate.is_default">Default</span> <span>{{rate.name}}</span> </option> </select> </div> </div> TEST JS: var app = angular.module("testApp", []); app.controller("MainCtrl", function($scope){ $scope.rates = [ { 'name': 'dolar', 'is_default': true}, { 'name': 'pound',

ng-click not working with ng-if

不羁的心 提交于 2019-12-03 06:20:47
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: <input type="text" ng-model="blub"/> <br/> <button ng-click="blub = 'xxxx'">X</button> <br/> <button ng-click="blub = 'yyyy'" ng-if="blub.length">Y</button> Controller: angular.module('test', []) .controller('Main', function ($scope) { // nothing to do here }); To play around: JSFiddle Use ng-show Instead of ng-if . That should work. Fiddle It doesn't work because ng-if is creating a new scope and interpreting your blub = 'yyyy' as