C# Angular js用标记替换html字符串

C# Angular js用标记替换html字符串,c#,angularjs,sitecore,C#,Angularjs,Sitecore,我有一个来自模型的值,它是一个相对巨大的html字符串。它还有一个标记,需要用Angular中的值替换。我想看看如何使收支平衡 我的Html <h2 class="sub-title"> @Model.WelcomeText </h2> 但是由于$scope.welcomeText在ng init中具有无效值,它在html本身中会中断 有没有关于如何实现这一点的建议?标题来自Sitecore CMS。我在JS中没有这个值,你可以简单地使用string的replace函数

我有一个来自模型的值,它是一个相对巨大的html字符串。它还有一个标记,需要用Angular中的值替换。我想看看如何使收支平衡

我的Html

<h2 class="sub-title"> @Model.WelcomeText </h2>
但是由于$scope.welcomeText在ng init中具有无效值,它在html本身中会中断


有没有关于如何实现这一点的建议?标题来自Sitecore CMS。我在JS中没有这个值,你可以简单地使用string的replace函数

角度模块(“应用程序”,[]) .controller(“ctrl”、[“$scope”、函数($scope){ $scope.WelcomeText=“Hi@@Name,欢迎访问我们的网站。单击了解更多详细信息。有关更多详细信息,请访问blah blah”; $scope.UserName=“ABC”; $scope.WelcomeText=$scope.WelcomeText.replace(“@@Name”,“$scope.UserName”); }]);
我最终做了这个。不确定这是否是理想的解决方案,但至少它是有效的

    //Added a div with hidden class to get the value.      
    <div class="hidden" id="inp-title-server" /> @Model.Title  </div>
    <h2 class="sub-title" data-ng-bind-html="$scope.header"></h2>

为什么不在$scope中创建一个变量作为
welcomeText
,getter应该具有逻辑或将@Name替换为$scope.Name,然后以有角度的方式使用它,而不是
@Model.welcomeText
使用
ng Model=$scope.welcomText
@PM。我不能。我没有Js中的价值。实际上,价值模型。标题来自CMS系统。您是否考虑过从Sitecore公开一个RESTful服务,您可以使用AJAX在内部调用该服务?这将取代您的Razor代码@Model.WelcomeText.@DougCouto-我考虑过这一点,但对于一个简单的标题文本来说,这太昂贵了。我做了些别的事情,结果成功了。我已经回答了这个问题。不是最好的解决方案,但很有效..我不能,因为我从服务器获取了值。在Javascript中没有这个值。
<h2 class="sub-title" ng-init= $scope.welcomeText('@Model.WelcomeText') </h2>
function welcomeText(str)
{
  return str.replace('@@Name',$scope.Name);
}
    //Added a div with hidden class to get the value.      
    <div class="hidden" id="inp-title-server" /> @Model.Title  </div>
    <h2 class="sub-title" data-ng-bind-html="$scope.header"></h2>
var title = $("#inp-title-server").text();
$scope.header = title.replace('@@Name', $scope.Name);