我们可以在$ sce.trustAsHtml中传递多个值

时间:2015-02-27 05:52:51

标签: angularjs

目前在我们的网站中有许多上下文,其中嵌入了链接。我们从json文件中获取这些上下文并嵌入为html。对于每个上下文,我们使用$ sce.trustAsHtml($ scope.localData.LANDING_PAGE.DESCRIPTION_WITH_LINK.SAMPLE_TEXT)。我们试图避免像这样的太多行。有没有办法避免/优化它?

$scope.Sample_Link = $sce.trustAsHtml($scope.localData.LANDING_PAGE.DESCRIPTION_WITH_LINK.SAMPLE_TEXT1); 
            $scope.Sample_Link2 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.DESCRIPTION_WITH_LINK.SAMPLE_TEXT_2); 
            $scope.Sample_Link3 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.SAMPLE_TEXT_3); 
            $scope.Sample_Link4 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.SAMPLE_TEXT_4);
            $scope.Sample_Link5 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.MODAL_WINDOWS.SAMPLE_TEXT_5);  
            $scope.Sample_Link6 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.MODAL_WINDOWS.SAMPLE_TEXT_6);
            $scope.Sample_Link7 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.MODAL_WINDOWS.SAMPLE_TEXT_7);
            $scope.Sample_Link8 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.MODAL_WINDOWS.SAMPLE_TEXT_8);
            $scope.Sample_Link9 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.MODAL_WINDOWS._9);
            $scope.Sample_Link10 = $sce.trustAsHtml($scope.localData.LANDING_PAGE.MODAL_WINDOWS.SAMPLE_TEXT_10);

1 个答案:

答案 0 :(得分:1)

你可以制作一个过滤器并在视图中使用它

app.filter('mysce', function($sce) { return $sce.trustAsHtml; });

<div ng-bind-html="value | mysce"></div>