AngularJS one-time binding with checking array length -


i'm trying use one-time binding when displaying content user if there values in array.

i'm using code:

app.controller('mainctrl', function($scope, $timeout) {   loadheroes = function() {     $scope.heroes = ['superman', 'batman', 'spider-man'];   };    $timeout(loadheroes, 5000);  }); 

and this:

<div ng-controller="mainctrl">   <pre ng-show="::heroes.length > 2">there few heroes!</pre>   <pre>{{::heroes | json}}</pre> </div> 

here plunker: http://plnkr.co/edit/k1kxutld8fowsoxc81sk?p=preview

but message not showing. tried set parentheses around array, it's not working either.

any idea how can achieve one-time binding checking array length?

use ng-if :

var app = angular.module('plunker', []);    app.controller('mainctrl', function($scope, $timeout) {    loadheroes = function () {      $scope.heroes = ['superman', 'batman', 'spider-man'];    };        $timeout(loadheroes, 5000);      });    
<!doctype html>  <html ng-app="plunker">      <head>      <meta charset="utf-8" />      <title>angularjs plunker</title>      <script>document.write('<base href="' + document.location + '" />');</script>      <link rel="stylesheet" href="style.css" />      <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.3/angular.js" data-semver="1.4.3"></script>      <script src="app.js"></script>    </head>      <body ng-controller="mainctrl">      <pre ng-if="::heroes.length">there few heroes!</pre>      <pre>{{::heroes | json}}</pre>          </body>    </html>

it "wait" variable set.

http://plnkr.co/edit/smbsmhmpulrfarbn0xtb?p=preview


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -