racamp101
racamp101

Reputation: 516

Angularjs ng-repeat with function returning html from a get

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.

Upvotes: 1

Views: 188

Answers (1)

Nish
Nish

Reputation: 1736

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>

Upvotes: 1

Related Questions