I have a problem with an user control (.ascx) loaded using jQuery ajax and AngularJs. Due legacy problems, i can't change the way that is loaded the user control. What is the problem? Let me explain you:
The AngularJs's controller has a watcher on the model change BUT due the model is getted using an ajax call, seems that the controller is not "launched" (the $watch doesn't runs when the user control is loaded) due async problems.
My first suggestion was, in the ajax's done process launch an event and, in the angularjs's controller, subscribe to this event but i don't know how can be done correctly and if there are another better options.
Any suggestions please? Thanks in advance.
Here are the code:
- The ajax call is the typical:
$.ajax( "example.php" ) .done(function() { alert( "success" ); })
- That user control "has" the model needed by AngularJs's directive:
<span class="price-value"> <%= Model.Price %> <asp:PlaceHolder ID="PriceLinkPlaceHolder" runat="server"> <price-details-link-directive data-price-parameters="<%= Server.HtmlEncode(Model.SerializedPriceParameters) %>">
</asp:PlaceHolder> </span>
- The HTML "result" of this user control:
<span class="price-value"> €449 <price-details-link-directive data-price-parameters="{ "priceDetailType": 2, "price": 449.0, "accommodationId": 38350, "departureDate": "01-01-0001", "transportType": 0, "duration": -1, "minOccupancy": -1, "maxOccupancy": -1, "roomType": "", "catalogBaseUrl": "" }"> </price-details-link-directive> </span>
- This is the angularjs's directive (priceDetailsDirective):
angularApp.directive('priceDetailsLinkDirective', function () { return { restrict: 'E', replace: true, templateUrl: '/angular/prices/price_details_link.html', controller: 'priceDetailsLinkController', scope: { priceParameters: '@' } }; });