admin管理员组文章数量:1344212
This is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="js/angular.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/angular-chart.js"></script>
</head>
<body>
<div ng-app="app">
<div ng-controller="BarCtrl">
<div ng-repeat="id in ids">
<canvas id="bar" class="chart chart-bar"
chart-data="{{id}}" chart-labels="labels"> chart-series="series"
</canvas>
</div>
</div>
</div>
<script type="application/javascript">
angular.module("app", ["chart.js"]).controller("BarCtrl", function ($scope) {
$scope.labels = ['2008', '2009', '2010', '2011', '2012'];
$scope.series = ['Series A', 'Series B'];
$scope.data = [];
$scope.data.push( [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
]);
$scope.ids = ["data[0]"];
});
</script>
</body>
</html>
This is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="js/angular.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/angular-chart.js"></script>
</head>
<body>
<div ng-app="app">
<div ng-controller="BarCtrl">
<div ng-repeat="id in ids">
<canvas id="bar" class="chart chart-bar"
chart-data="{{id}}" chart-labels="labels"> chart-series="series"
</canvas>
</div>
</div>
</div>
<script type="application/javascript">
angular.module("app", ["chart.js"]).controller("BarCtrl", function ($scope) {
$scope.labels = ['2008', '2009', '2010', '2011', '2012'];
$scope.series = ['Series A', 'Series B'];
$scope.data = [];
$scope.data.push( [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
]);
$scope.ids = ["data[0]"];
});
</script>
</body>
</html>
When I run the code in Chrome, the console wrote:
[$parse:syntax] Syntax Error:
Token '{' invalid key at column 2 of the expression [{{id}}] starting at [{id}}].
<input value="{{id}}">
seems to be ok, but chart-data="{{id}}"
is causing the Syntax Error. Any idea why that would happen?
1 Answer
Reset to default 11chart-data
should not have expression, it should have a scope variable binding.
<canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels" chart-series="series">
</canvas>
{{ ... }}
means you're evaluating an expression, for example {{1+1}}
or printing (not passing) a variable {{id}}
. However, to pass a variable, you should not wrap it in an expression when you're assigning it to a property.
本文标签:
版权声明:本文标题:javascript - Syntax Error: Token '{' invalid key at column 2 of the expression [{{id}}] starting at [{id}}]? - S 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743747219a2531980.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论