I am currently working on an application in AngularJS and I have a function that removes #(hashes) and turns them into links.
$scope.getAllHashes = function(event){
var x = event;
var collect = '';
var link = '';
for (i = 0; x.length > i; i++) {
//remove #
link = x[i].substr(1);
collect += "<a href='#/search/" + link + "'>" + x[i] + "</a> ";
}
return document.getElementsByClassName('hashes').innerHTML = collect;
};
Instead of displaying as links:
<a href='#/search/aaa'>#aaa</a> <a href='#/search/bbb'>#bbb</a> <a href='#/search/cccc'>#cccc</a>
It is showing as text:
#aaa #bbb #ccc
The data comes from this array:
$scope.events =
[
{
id: 1,
datetime: 'FRI, 6 NOV 10:00 AM',
title: 'Event Title goes here - lalelalela',
address: {
road: '650 Address Rd',
city: 'Toronto',
state: 'Ontario',
postal: 'A1B1C3',
country: 'CA'
},
hashes: ['#aaa','#bbb','#cccc']
}, .....
This is the section of code from the HTML source:
<span class="hashes ng-binding">
<a href='#/search/aaa'>#aaa</a> <a href='#/search/bbb'>#bbb</a> <a href='#/search/cccc'>#cccc</a>
</span>
I am unsure why it is not displaying as HTML elements.