Hi I'm fairly new to to Angular development and I wanted to know if 
something I'm going is the the most efficient and not likely to cause any 
trouble down the road. If this is the wrong place for this kind of question 
I apologize and if you could point me to the right place I'd appreciate it.

The site uses Angular's client-side routing. A requirement of the project 
is that all the body text for the site be served from a flat json file. For 
most of the site this is not a problem. The main index file hits the 
IndexController and fetches the file in the following way:

TextFactory.get.query(function (response) {
    $scope.textDump= response;
});

This gets the site's text on initial page load and then as the browser gets 
routed around the site it doesn't have to make the $request call ever again 
to continue using the text. On one of the pages (privacy policy) there is 
an expectation to be able to insert html formatting directly in the json 
file. To support this I'm doing the following the terms of service 
controller:

app.controller('TermsOfServiceController', ['$scope', '$sce', function 
($scope, $sce) {
    $scope.$watch("textDump.tos", function (new_val, old_val) {
       if (angular.isDefined(new_val)) {
          $scope.pageContent = $sce.trustAsHtml($scope.textDump.tos);
       }
    });
}]);

I had to do this because there was a race condition where textDump.tos had 
not yet received the json file from the CDN by the time the 
TermsOfServiceController tried to use it. Are there any caveats to this 
approach that I should be aware of? Is there a better way to achieve the 
same result? Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to