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.

1

3 Answers 3

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

You gave me perfect solution
0

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

$scope.isArray = function(value){ return Array.isArray(value) }

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.