I am using angularjs and i have a terms of use document in a text file which i was to render into html. Any recommendations on how to read that text file and display it using html or display it to the user? Thanks
Asked
Active
Viewed 1.6k times
-1
-
See http://stackoverflow.com/questions/18839048/how-to-read-a-file-in-angularjs – schellingerht Jul 23 '15 at 21:18
1 Answers
6
Simplest way is using ng-include
. If you need to use the line breaks in the text file within your view wrap in a <pre>
tag
<h3>Terms</h3>
<ng-include src="'terms.txt'"></ng-include>
OR
<pre ng-include src="'terms.txt'"></pre>

charlietfl
- 170,828
- 13
- 121
- 150
-
1@Charlieti thanks for the demo above. It works well. But i cant get it to work on my side. here is the code i have and it shows a jumbuton-like area with a grey color and nothing inside. It also scrolls up and down but its all grey. I dont why .
Terms
-
not the extra quotes inside `src` .. looks strange but is needed if want to load from server url – charlietfl Jul 24 '15 at 16:15
-
-
not sure why...is that the right path to the file? Can inspect the actual ajax request in browser dev tools network tab to see if it is made and succeeds and what is returned – charlietfl Jul 24 '15 at 16:17
-
I always get the error that `ng-include` is not a known element. – stefanbschneider Jul 31 '19 at 13:35