我正在用模态窗口构建一个AngularJS web应用程序。在模式窗口中,我可以显示一个JQuery Flot实时图,与此类似: http://people.iola.dk/olau/flot/examples/realtime.html如何将AngularJS变量传递给Javascript?
我的网站显示多个用户,但用户数量可能因所选内容而异。我喜欢为每个用户显示一张图表。这是我难过的地方。
我从http://people.iola.dk/olau/flot/examples/realtime.html复制的Javascript代码,并把它放在/js/flot/flot.user.js,并取得了这些变化:
//$(function() {
function flotChart(user_ID) {
...
//var plot = $.plot($("#placeholder"), [ getRandomData() ], options);
var plot = $.plot($("#chart_" + user_ID), [ getRandomData() ], options);
…
我AngularJS web应用程序有这样的代码:
在index.app.html:
<!DOCTYPE HTML>
<html ng-app="app">
...
<body ng-controller="AppCtrl">
...
<div class="container">
<div ng-view></div>
</div>
...
在模板(的index.html):
...
<!-- Modal window -->
<script src="/js/flot/flot.user.js"></script>
<table class="table table-condensed">
<tr ng-repeat="user in users">
<td ng-click="href('#/profile/'+user.user_ID)" data-dismiss="modal">{{user.user_name}}</td>
<td>
<script type="text/javascript">
flotChart({{user.user_ID}});
</script>
<div id="chart_{{user.user_ID}}" style="width:100%;height:150px;"></div>
</td>
...
如上所示,我需要将{{user.user_ID}}传递给flotChart(user_ID),但flotChart({{user.user_ID}})不起作用。
有人可以提出一个解决方案吗?
@blesh喜: 我已经在我的index.app.html文件中的BODY标签。我不认为我可以将另一个BODY标签放入我的index.html(模板)文件中,我可以吗?我的模板文件以HEADER标签开头。 userId的值在我的index.html(模板)文件中。 ng-repeat会创建多行用户,每个用户都有自己的userId。我没有看到如何传递给Javascript代码。我假设你建议我忘记将{{userId}}中的值传递给HTML文件中的Javascript代码? AngularJS有多个JS文件。我应该把你的代码放到哪个JS文件中? – Curt