javascript - Remove DOM elements using Angular filter but without jQuery -


i'm starting learn angular , have been getting grips basics of it. i've come unstuck, wider knowledge of js pretty limited.

i'm creating feed brings in data json file. 1 of items wish bring in string html inside:

"description": " <p><a href=\"https://www.flickr.com/people/71256895@n00/\">tomylees<\/a> posted photo:<\/p> <p><a href=\"https://www.flickr.com/photos/71256895@n00/20384585533/\" title=\"american sweet potatos img_6026\"><img src=\"https://farm1.staticflickr.com/608/20384585533_4141b76f92_m.jpg\" width=\"240\" height=\"180\" alt=\"american sweet potatos img_6026\" /><\/a><\/p> <p>going farm shop.<br /> rose farm shop, rose farm cottages, haine rd, ramsgate ct12 5ag.<br /> saturday, 29th august 2015, ramsgate, kent.<\/p>", 

i'm parsing html view using ngsanitize , ng-bind-html without issue.

where coming unstuck, every string of html starts 2 <p> elements don't want display.

basically want create filter this:

var trim = require('trim'); var $ = require('jquery');  angular.module('flickrfeed')     .filter('removepara', function () {         return function(input) {             var $html = $('<div></div>').append($.parsehtml(input));             $html.find('p:nth-child(1), p:nth-child(2)').remove();             var output = trim($html.text());             return output || 'no description available.';         };     }); 

but, don't want use jquery, feels overkill tiny part. i'm aware filter won't need parse html, ngsanitize takes care of before hits filter (is why i'm struggling?).

main question: how isolate , remove first 2 <p> elements? conditional 'no description available' added bonus, i'll settle getting rid of 2 paragraphs.

cheers,

jamie.

behind scene angular use jquery, wrap functions differntly

angularjs documentation element

var = angular.element("<div>").append(angular.element(input)) a.find('p:nth-child(1), p:nth-child(2)').remove() var output = trim(a.text()); return output || 'no description available.'; 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -