如何application/ld+json script在AngularJS中使用动态构建的JSON对象创建标记.
这就是我需要脚本标签的样子
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Place",
"geo": {
"@type": "GeoCoordinates",
"latitude": "40.75",
"longitude": "73.98"
},
"name": "Empire State Building"
}
</script>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码,但我无法让它工作:
HTML
<div ng-controller="TestController">
<script type="application/ld+json">
{{jsonId|json}}
</script>
{{jsonId|json}}
</div>
Run Code Online (Sandbox Code Playgroud)
调节器
var myApp = angular.module('application', []);
myApp.controller('TestController', ['$scope', function($scope) {
$scope.jsonId = {
"@context": "http://schema.org",
"@type": "Place",
"geo": {
"@type": "GeoCoordinates",
"latitude": "40.75",
"longitude": "73.98"
},
"name": "Empire State Building"
};
}]);
Run Code Online (Sandbox Code Playgroud)
脚本标记内的表达式不会执行.脚本标记外部的表达式正确执行并显示JSON
请看jsfiddle