0

Example: The picture-gallery-directive retrieves pictures and passes them to the scope:

var galleryBootstrapData = bootstrapDataService.get('galleryBootstrapData');
$scope.galleryPictures = galleryBootstrapData.pictures;

The picture-gallery-template renders the pictures and as shown below the number of pictures:

<div ng-if="galleryPictures.length && galleryPictures.length>0" >{{galleryPictures.length}}</div>

Is it good practice to check the scope-variables for undefined from within the template?

Maral
  • 3
  • 4

1 Answers1

0

It isn't needed. Since so much of our data is handled asynchronously angular already recognizes this and will fail silently in the view when it encounters undefined variables

You could replace what you have with

<div ng-if="galleryPictures.length" >

Checking for length > 0 isn't needed either since zero is falsy

charlietfl
  • 170,828
  • 13
  • 121
  • 150