1

I have a directive which takes an object, and the directive is under a element which contain ng-repeat on array of objects, what i want try to achieve is to reorder the array and passed the object based on some object property (which is a numeric one say precedence )

<elem ng-repeat="element in array |  orderBy:'precedence ' ">
<my-directive item='element'></my-directive>
</elem>

so what i want is that all the element to be passed to directive must be reorder based on precedence.

and also inside each object there will be array of sub-objects with same blueprint (clone of parent object).

Sohail Faruqui
  • 442
  • 11
  • 27

2 Answers2

0

According to documentation.

<div ng-app="myApp" ng-controller="Ctrl">
    <div ng-repeat="card in myCards | orderBy:'firstName'">
        <my-directive>{{card.firstName}} {{card.lastName}}</my-directive>
    </div>
</div>

angular.module('myApp', [])
    .controller('Ctrl', function($scope) {
        $scope.myCards = [
            {firstName: 'John', lastName: 'Smith'},
            {firstName: 'Eleanor', lastName: 'Rigby'},
            {firstName: 'Maxwell', lastName: 'Hammer'},
            {firstName: 'Buzz', lastName: 'Aldrin'},
            {firstName: 'Neil', lastName: 'Armstrong'}
        ];
    });

More detail how can you create your own filter you can read here.

0

You need to add from which controller you're objects are coming from, and lack the angular expression within you directive element, so anything could be displayed.

<my-directive> {{ your array element }} </my-directive>
desicne
  • 851
  • 2
  • 9
  • 23
  • I do not need to display them, I need to pass it to my directive isolated scope dos some processing on them and show the results, on displaying them the way you mentioned it works, but once it passes to directive it looses order!!! what I am trying to achieve is to build UI- element and based on precedence the should be display, and having outer ng-repeat is must for me. – Sohail Faruqui Nov 23 '15 at 06:30