You need to compile the template again in End_Request from PageRequestManager. I used a div with id so that I can reference the element of interest in the End_Request function.
Javascript code:
var mod = angular.module("myApp", []); mod.controller("MainController", function ($scope, $compile) { $scope.data = {}; $scope.data.world = "world"; Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args) { var elem = angular.element(document.getElementById("angularTemplate")); elem.replaceWith($compile(elem)($scope)); $scope.$apply(); }); });
Aspx code:
<body ng-app="myApp" ng-controller="MainController"> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div id="angularTemplate"> Hello, {{data.world}} </div> <asp:Button ID="btnUpdate" runat="server" Text="Update Me" /> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body>
When you click the Update Me button, the template will store Hello, world. The key should also call $ scope. $ Apply () in End_Request as this is technically done outside of angular.
source share