1

I'm new to angularjs and trying to figure out what is going on here.

I have ng-repeat:

<li class="widget flip-container" ng-repeat="widget in widgets">
                 <div class="widgetContent" ng-bind-html="getData(widget.UserWidgetId,widget.Url)">
                 </div>
</li>

getData is a function:

 $scope.getData = function(id, url) {
            if (url == null || url == "") return "";                

            return userWidgetsFactory.getWidgetHtml(url).success(function(results) {
                return results;
            });
        };

the factory:

app.factory("userWidgetsFactory", function($http) {
        var factory = {};
        factory.getWidgetHtml = function(url) {
            return $http.get(url);
        };
        return factory;
    });

My problem is that the function is repeatedly called and wont stop. I know I'm doing to this so wrong.

4
  • what is widgets and where does it come from? Commented Apr 14, 2014 at 19:31
  • widgets is a collection of objects that look like this: {"UserWidgetId":"77485504-7796-42b6-8b8a-c0e41e89ac69","UserId":0,"Theme":null,"WidgetId":"5926d2cc-4e6b-452c-951f-05a1aca6d627","Url":"/web/WeatherWidget/index","Col":1,"Row":1,"SizeX":1,"SizeY":2,"SectionId":"00000000-0000-0000-0000-000000000000","Name":"Weather","Icon":"fa-sun-o","UseRandomImage":false,"BackgroundImage":null,"Section":null} Commented Apr 14, 2014 at 19:35
  • Try binding html safely. stackoverflow.com/questions/19415394/… Commented Apr 14, 2014 at 20:05
  • that didn't seem to help. now i just get a blank nothing instead of the "{}" Commented Apr 15, 2014 at 0:02

1 Answer 1

1

Try this ... ng-bind-html adds a watch.

<li class="widget flip-container" ng-repeat="widget in widgets" ng-init="testdata = getData(widget.UserWidgetId,widget.Url)">
                 <div class="widgetContent"> {{testdata}}
                 </div>
</li>
Sign up to request clarification or add additional context in comments.

3 Comments

that stopped the repeating but all I get is "{}" showing up in each element
What is returned from getData? Make sure correct result is returned.
please see the getData function in my question. the data returned from the server is html

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.