首先我们看这样一个实例:
// Filter
sl.filter('titleFilter', function() {
return function(title, id) {
var url = '/public/article#/' + id;
return '<a href="' + url + '">' + title + '</a>';
};
});
使用实例:(Works good)
<h6 class="news-title" ng-bind="v.title | titleFilter:v.id"></h6>
另一实例:(Html插入, It doesn't work, WHY?)
$scope.getHtml = function (html) { return $sce.trustAsHtml(html); };
<h6 class="news-title" ng-bind-html="getHtml(v.title | titleFilter:v.id))"></h6>
转换思路:
// Controller $scope function $scope.getTitle = function(title, id) { var url = '/public/article#/' + id; return '<a href="' + url + '">' + title + '</a>'; }
(Work perfect)
<h6 class="news-title" ng-bind-html="getHtml(getTitle(v.title, v.id))"></h6>