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.

racamp101
  • 506
  • 2
  • 12
  • what is `widgets` and where does it come from? – Luke Apr 14 '14 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} – racamp101 Apr 14 '14 at 19:35
  • Try binding html safely. http://stackoverflow.com/questions/19415394/with-ng-bind-html-unsafe-removed-how-do-i-inject-html#answer-19417443 – Nish Apr 14 '14 at 20:05
  • that didn't seem to help. now i just get a blank nothing instead of the "{}" – racamp101 Apr 15 '14 at 00:02

1 Answers1

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>
Nish
  • 1,656
  • 1
  • 10
  • 19