justaphase
asked on
Angularjs - How to use expression inside script tag
Hi everyone,
How can i do this?:
Angular doesn't render nothing inside the script tag, and i need that for google.
Is it possible?
How can i do this?:
<div class="row" ng-controller="singleEventCtrl">
<div class="col-md-9"> ...... more html code .....
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Event",
"name": '{{event[0].titulo}}',
"startDate" : "{{event[0].event_dataini_iso8601 | date:'yyyy-MM-dd'}}",
"endDate" : "{{event[0].event_dataini_iso8601 | date:'yyyy-MM-dd'}}",
"url" : "http://example.com/tourdates.html",
"location" :
{
"@type" : "Place",
"name" : "{{event[0].tb_town_townname}}"
}
}
</script>
</div>
</div>
Angular doesn't render nothing inside the script tag, and i need that for google.
Is it possible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ambience,
in the DOM, the {{event[0].something}} is note replaced with the value in the DOM.. doesn't work :\
Not outside the controller or inside..
As to gelonida answer i think it may work, but gonna need some time to implement and test..
in the DOM, the {{event[0].something}} is note replaced with the value in the DOM.. doesn't work :\
Not outside the controller or inside..
As to gelonida answer i think it may work, but gonna need some time to implement and test..
Oh OK, sorry I forgot to update that part. I was thinking of changing it to
<script type="application/ld+json" >
{
"@context": "http://schema.org",
"@type": "Event",
"name": event[0].titulo,
This snippet now uses the object var event, which is fetched from angular scope in the other script block.
<script type="application/ld+json"
{
"@context": "http://schema.org",
"@type": "Event",
"name": event[0].titulo,
This snippet now uses the object var event, which is fetched from angular scope in the other script block.
ASKER
ambience, it may work if you get the values with javascript, but not for google.
google is not going to execute javascript to get the values, he is going to get the values inside the brackets 'some value' and not event[0].titulo.
I know google is able to get the page rendered after Angularjs finishes it, i tested it.
But i don't think is going to get this json with the values like that... because if you make inspect element in google chrome you can see the {{event.something}} transformed in real values. But not the: "name": event[0].titulo. inside the script tag.
It stays event[0].titulo
google is not going to execute javascript to get the values, he is going to get the values inside the brackets 'some value' and not event[0].titulo.
I know google is able to get the page rendered after Angularjs finishes it, i tested it.
But i don't think is going to get this json with the values like that... because if you make inspect element in google chrome you can see the {{event.something}} transformed in real values. But not the: "name": event[0].titulo. inside the script tag.
It stays event[0].titulo
ASKER
Thx! worked!
Open in new window