我正在用模態窗口構建一個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