从数据库Sqlite到AngularJS HTML

huangapple go评论99阅读模式
英文:

From Database Sqlite to AngularJS HTML

问题

  1. 我试图将来自数据库的HTML代码转换为我的页面。
  2. @foreach (DataRow Row in DT.Rows)
  3. {
  4. <p>@Row.ItemArray[1]</p>
  5. <span ng-bind-html="mydata"></span>
  6. <hr />
  7. <script type="text/javascript">
  8. var app = angular.module('magnos', ['ngSanitize']);
  9. app.controller('mycont', function ($scope) {
  10. $scope.mydata = '@Row.ItemArray[2]';
  11. });
  12. </script>
  13. }
  14. 但是`@Row.ItemArray[2]`始终返回字符串,而不是像这样的HTML`<h1>Magnos</h1>`
  15. 我希望将HTML代码写成HTML代码在我的页面上,这样Magnos标题会显示为标题。
英文:

I trying to convert HTML code from database to my page.

  1. @foreach (DataRow Row in DT.Rows)
  2. {
  3. <p>@Row.ItemArray[1]</p>
  4. <span ng-bind-html="mydata"></span>
  5. <hr />
  6. <script type="text/javascript">
  7. var app = angular.module('magnos', ['ngSanitize']);
  8. app.controller('mycont', function ($scope) {
  9. $scope.mydata = '@Row.ItemArray[2]';
  10. });
  11. </script>
  12. }

But the @Row.ItemArray[2] is always return string, not HTML like this
<h1>Magnos</h1>

I want the HTML code to write as HTML code in my page, so the Magnos header show as header.

答案1

得分: 0

感谢大家,我已经找到了解决方案,
以下是解决方案:-

  1. @foreach (DataRow Row in DT.Rows)
  2. {
  3. <h2>@Row.ItemArray[1]</h2>
  4. <br />
  5. <span ng-bind-html="get_pre('@Row.ItemArray[2]');"></span>
  6. <hr />
  7. <script type="text/javascript">
  8. var app = angular.module('magnos', []);
  9. app.controller('mycont', function ($scope, $sce) {
  10. $scope.get_pre = function (x) {
  11. return $sce.trustAsHtml(x);
  12. };
  13. });
  14. </script>
  15. }
英文:

Thank you all I have found the solution,
Heres the Solution:-

  1. @foreach (DataRow Row in DT.Rows)
  2. {
  3. <h2>@Row.ItemArray[1]</h2>
  4. <br />
  5. <span ng-bind-html="get_pre('@Row.ItemArray[2]');"></span>
  6. <hr />
  7. <script type="text/javascript">
  8. var app = angular.module('magnos', []);
  9. app.controller('mycont', function ($scope, $sce) {
  10. $scope.get_pre = function (x) {
  11. return $sce.trustAsHtml(x);
  12. };
  13. });
  14. </script>
  15. }
  16. </details>

huangapple
  • 本文由 发表于 2023年6月5日 17:25:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定