英文:
From Database Sqlite to AngularJS HTML
问题
我试图将来自数据库的HTML代码转换为我的页面。
@foreach (DataRow Row in DT.Rows)
{
<p>@Row.ItemArray[1]</p>
<span ng-bind-html="mydata"></span>
<hr />
<script type="text/javascript">
var app = angular.module('magnos', ['ngSanitize']);
app.controller('mycont', function ($scope) {
$scope.mydata = '@Row.ItemArray[2]';
});
</script>
}
但是`@Row.ItemArray[2]`始终返回字符串,而不是像这样的HTML:`<h1>Magnos</h1>`。
我希望将HTML代码写成HTML代码在我的页面上,这样Magnos标题会显示为标题。
英文:
I trying to convert HTML code from database to my page.
@foreach (DataRow Row in DT.Rows)
{
<p>@Row.ItemArray[1]</p>
<span ng-bind-html="mydata"></span>
<hr />
<script type="text/javascript">
var app = angular.module('magnos', ['ngSanitize']);
app.controller('mycont', function ($scope) {
$scope.mydata = '@Row.ItemArray[2]';
});
</script>
}
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
感谢大家,我已经找到了解决方案,
以下是解决方案:-
@foreach (DataRow Row in DT.Rows)
{
<h2>@Row.ItemArray[1]</h2>
<br />
<span ng-bind-html="get_pre('@Row.ItemArray[2]');"></span>
<hr />
<script type="text/javascript">
var app = angular.module('magnos', []);
app.controller('mycont', function ($scope, $sce) {
$scope.get_pre = function (x) {
return $sce.trustAsHtml(x);
};
});
</script>
}
英文:
Thank you all I have found the solution,
Heres the Solution:-
@foreach (DataRow Row in DT.Rows)
{
<h2>@Row.ItemArray[1]</h2>
<br />
<span ng-bind-html="get_pre('@Row.ItemArray[2]');"></span>
<hr />
<script type="text/javascript">
var app = angular.module('magnos', []);
app.controller('mycont', function ($scope, $sce) {
$scope.get_pre = function (x) {
return $sce.trustAsHtml(x);
};
});
</script>
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论