0

I've got several HTML files and I need to extract text content of given elements in these html files and get it into angular as variables.

I've decided to use angular $templateRequest to get each HTML file, and $templateCache to store them in cache. I was hoping this way I could use angular or jQuery/jQueryLite selector to access these cached templates and get a specific element contents by element ID. But when it comes to retrieving the a given element text from given cached template, I'm hitting the wall.

$templateRequest(htmlFileUrl.html).then(function(htmlFile) {
   $templateCache.put(htmlFileName, htmlFile);
   var template = $templateCache.get(name);
   var elementId = '#some_id'; //element present in htmlFileUrl.html
   var elementText;
   // Assign text value of elementId to elementText SOMEHOW
   console.log(elementText) // Should print text of elementId
});
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Rado Koňuch
  • 375
  • 2
  • 8
  • 16

1 Answers1

0

Assuming you're using jQuery along angularjs, you can just pass template content to it (this won't affect your DOM) and do a lookup you'd normally do with jQuery:

var template = $( $templateCache.get(name) );
var elementId = '#some_id';
var elementText = template.find(elementId).text();
console.log(elementText);
WTK
  • 16,583
  • 6
  • 35
  • 45
  • Hey, unfortunately it didn't work. Maybe if you could set it up on plunker, so maybe I can see what I'm during wrong. – Rado Koňuch Aug 27 '15 at 22:07
  • Better to do it other way around - you set it up and we can go into and try to fix it :) – WTK Aug 31 '15 at 06:18