gpt4 book ai didi

javascript - AngularJS "not well-formed",但仍显示在 Firefox 中

转载 作者:行者123 更新时间:2023-11-28 08:36:00 25 4
gpt4 key购买 nike

我刚刚开始使用 AngularJS 在网页上动态显示 json 数据。我之前已经将 ng-repeat 与外部 json 文件一起使用,效果很好,但是当我在数组之前添加数据时,它不再在 IE 和 chrome 中工作,但在 Firefox 中显示,并出现 firebug 错误。我相信我的语法是正确的,但显然有些问题,而且我无法弄清楚。

这是我的确切代码:

HTML

<html ng-app>
<script src="angular.min.js"></script>
<script src="dumctrl.js"></script>
<head>
<title>AngularJS Dummy Page</title>
</head>
<body ng-controller="AppCtrl">
<table border="1px">
<tr>
<th>{{log.name}}</th>
<th>{{log.xname}}</th>
<th>{{log.yname}}</th>
</tr>
<tr>
<th>ID</th>
<th>X</th>
<th>Y</th>
</tr>
<tr ng-repeat="entry in log.entries">
<td>{{entry.id}}</td>
<td>{{entry.x}}</td>
<td>{{entry.y}}</td>
</tr>
</table>
</body>
</html>

dumctrl.js

function AppCtrl($scope, $http) {
$http.get('dummy.json').success(function(data) {
$scope.log = data;
});
}

虚拟.json

{
"name":"dummy",
"xname":"xdummy",
"yname":"ydummy",
"entries":[
{
"id":0,
"x":0,
"y":0
},
{
"id":1,
"x":1,
"y":0
}
]
}

json 已验证,它显示了 ff 中的预期输出,我只是不知道出了什么问题。

最佳答案

我认为问题出在 [{}]

之间的空格

我刚刚创建了一个 JSFiddle并且效果很好:

var myApp = angular.module('myApp',[]);
function myCtrl($scope)
{
$scope.log = {
"name":"dummy",
"xname":"xdummy",
"yname":"ydummy",
"entries":[{
"id":0,
"x":0,
"y":0
},
{
"id":1,
"x":1,
"y":0
}]
};

}

关于javascript - AngularJS "not well-formed",但仍显示在 Firefox 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21174313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com