Copied to clipboard

Flag this post as spam?

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


  • stephen 67 posts 108 karma points
    Oct 02, 2019 @ 12:19
    stephen
    0

    Back Office ng-repeat repeats itself

    I created a simple Back Office datatype with a js controller, resource,html, manifest and c# controller but the ng-repeat fires twice.

    html:

      <div ng-controller="My.custom02">
            <div ng-repeat="person in people" >
                    <p>First Name: {{person.fname}} {{people.length}}</p>
            </div>
      </div>
    

    js controller:

    custom02.GetAllData().then(function (response) {
       $scope.people = response.data;
    })
    

    js resource

    angular.module('umbraco.resources').factory('custom02', function ($http) {
    return {
        GetAllData: function () {
            return $http.get("backoffice/Dignity/BackOfficeApi/getName");
        }
    }
    

    })

    The BackOfficeApi/getName just returns a simple string ("John")

    The response.data contains the correct data ("John") and the same goes for $scope.people but the ng-repeat indicates the people.length is 4.

    One suggestion I have seen is that the angular library is being called multiple times but not sure if that is the case.

    I have created similar in previous Umbraco versions so wondering if it is something to do with V8.

  • Kevin Jump 1516 posts 9723 karma points MVP 3x c-trib
    Oct 02, 2019 @ 12:46
    Kevin Jump
    0

    Hi Stephen,

    i think you are getting this result because your API controller is returning a string and not an array of strings.

    so when the angular gets "john" and you to a repeat it is looping through the characters, and that is what gives you the length 4

    if instead you API controller returns an array (even just of one name) the angular will get ["john"] and that is a single element, so should just show the single name.

  • stephen 67 posts 108 karma points
    Oct 02, 2019 @ 12:53
    stephen
    0

    Hi thanks. That makes sense. I'll check it out.

Please Sign in or register to post replies

Write your reply to:

Draft