Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Graham Davis 110 posts 376 karma points
    Nov 17, 2019 @ 14:31
    Graham Davis
    0

    How to remove duplates in ng-repeat

    I have an ng-repeat with duplicates that need to be removed. According to the doc, the unique function is a part of Angular UI, which does not appear to be included in Umbraco. Is there a way to add it Angular UI? How do I remove the duplicates?

        <div style="float:left;margin-right:15px; ">
            <h4>Class</h4>
            <select id="SearchClass" ng-model="searchTerm" size="20" style=" height:500px;">
                <option ng-repeat="g in model.availableItems | unique: 'model.availableItems.config.searchClass'" value="{{g.config.searchClass}}">{{g.config.searchClass}}n</option>
            </select>
        </div>
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Nov 22, 2019 @ 00:46
    Alex Skrypnyk
    0

    Hi Graham

    Maybe you can add a custom filter to make it works:

    // here we define our unique filter
    testApp.filter("unique", function() {
      // we will return a function which will take in a collection
      // and a keyname
      return function(collection, keyname) {
        // we define our output and keys array;
        var output = [],
          keys = [];
    
        // we utilize angular's foreach function
        // this takes in our original collection and an iterator function
        angular.forEach(collection, function(item) {
          // we check to see whether our object exists
          var key = item[keyname];
          // if it's not already part of our keys array
          if (keys.indexOf(key) === -1) {
            // add it to our keys array
            keys.push(key);
            // push this item to our final output array
            output.push(item);
          }
        });
        // return our array which should be devoid of
        // any duplicates
        return output;
      };
    });
    
  • Graham Davis 110 posts 376 karma points
    Nov 22, 2019 @ 01:38
    Graham Davis
    0

    Thank you Alex.

    I am trying to modify the Content Picker in Umbraco's BackOffice and my knowledge of Angular is Basic. How do I get that to work with / in the controller Umbraco.Overlays.ItemPickerOverlay?

    see: https://our.umbraco.com/forum/using-umbraco-and-getting-started/99913-how-to-create-custom-itempickerhtml

Please Sign in or register to post replies

Write your reply to:

Draft