大佬教程收集整理的这篇文章主要介绍了使用AngularJS进行文本格式化,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用PHP PDO echo json_encode输出我的数据库查询结果.
所以我想我只是在我的文本中插入一些html标记(一些标题和段落标记),然后让浏览器对其进行格式化,但现在我的浏览器将html标记显示为文本.
是否有AngularJS过滤器可以轻松完成此操作?我通过文档搜索但无法找到类似的东西.
我真的不想为我在数据库中存储的每一篇文章编写html标记,但我不知道如何做到这一点.在此之前,我刚刚编写了一个自定义jQuery函数,用< br>代替了行制动器.等等.
这是我的代码:
HTML:
<div id="full-article" ng-repeat="fArticle in fullArticle" ng-show="!Feed" ng-hide="Feed"> <h1>{{ fArticle.title }}</h1> <h3>{{ fArticle.posted | date:"dd.Mm.yyyy"}}</h3> <p>{{ fArticle.body }}</p> <button ng-click="BACkToFeed()">BACk to articles</button> </div>
控制器:
'use Strict'; angular.module('ptcAngularJsApp') .controller('ArticlesCtrl',function ($scope,$http) { // $scope.fullArticle = []; $scope.Feed = true; $scope.message = ''; $scope.findArticleBytitle = function(articlE) { $http.post('http://localhost/PTC_db_PHP/article_by_title.PHP',article.titlE). success(function(responsE) { $scope.fullArticle = response; $scope.Feed = false; }). //end http post response error(function(err) { console.log(err); }); //end http post error }; //end findArticleBytitle }); //end .controller
$scope.fullArticle = response; for(var x = 0; x < $scope.fullArtcile.length; x++){ $scope.fullArticle[x].trustedBody = $sce.trustAsHtml($scope.fullArticle[x].body) }
然后制作你的html:
<p data-ng-bind-html="fArticle.trustedBody"></p>
你可以在这里阅读:https://docs.angularjs.org/api/ng/directive/ngBindHtml并查看以下答案:With ng-bind-html-unsafe removed,how do I inject HTML?
以上是大佬教程为你收集整理的使用AngularJS进行文本格式化全部内容,希望文章能够帮你解决使用AngularJS进行文本格式化所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。