1

This is my index page

<li class="active" ng-repeat="items in menuItems">
    <span ng-if="angular.isArray(items)">
        <a href="" class="act">{{items}}</a>
    </span> 
</li>

This is my controller

app.controller('mainController', function($scope) {
  $scope.assests = 'include/assests.html' ;
  $scope.menu = 'include/menu.html' ;
  $scope.footer = 'include/footer.html' ;
  $scope.menuItems = [ 'a' , ['xyz'] , ['abc'] ];
});

MenuItems is mix of array and values , but angular.isArray(items) neither evaluate true nor false.

Mistalis
  • 17,793
  • 13
  • 73
  • 97
wasim beg
  • 73
  • 13

3 Answers3

3

<span ng-if="angular.isArray(items)"> will looks for something in your scope named: $scope.angular.isArray() ; that obviously does not exists.

I would suggest you to do the following:

<span ng-if="isArray(items)">

And in your controller, define this function:

$scope.isArray = function(obj) {
    return angular.isArray(obj);
}
Mistalis
  • 17,793
  • 13
  • 73
  • 97
0

just put ng-if="isArray(items)" and then in your controller

$scope.isArray = function(value){ return Array.isArray(value) }
scary_devil
  • 268
  • 4
  • 19
0

There is other solution, but i won't recomend it to use (it's better to have wrap over angular.functions and do not have direct access from view to angular, but sometime, it could be usefull).

You can set $scope.angular property with angular value like this:

(function(angular) {
 'use strict';

  var app = angular.module('app', []);

  app.controller('MainCtrl', ['$scope', function($scope) {
        $scope.angular = angular;
  }]);  
})(angular);

In this case access from view like angular.isArray will be transformed to $scope.angular.isArray.

Maxim Zhukov
  • 10,060
  • 5
  • 44
  • 88