加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何将AngularJS变量传递给Javascript?

发布时间:2020-12-17 18:07:23 所属栏目:安全 来源:网络整理
导读:我正在构建一个带模态窗口的AngularJS Web应用程序.在模态窗口中,我可以显示一个 JQuery Flot实时图表,类似于: http://people.iola.dk/olau/flot/examples/realtime.html 我的网站显示多个用户,但根据所选内容,用户数可能会有所不同.我想为每个用户显示一个
我正在构建一个带模态窗口的AngularJS Web应用程序.在模态窗口中,我可以显示一个 JQuery Flot实时图表,类似于:
http://people.iola.dk/olau/flot/examples/realtime.html

我的网站显示多个用户,但根据所选内容,用户数可能会有所不同.我想为每个用户显示一个图表.这是我难倒的地方.

我从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),options);
…

我的AngularJS网络应用程序有以下代码:

在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建议使用指令,但建议稍微处理一下(对不起,我现在没有带宽).对于你拥有的代码,我认为你所需要的只是一个小小的调整.

<td ng-click="href('#/profile/{{user.user_ID}}')" data-dismiss="modal">{{user.user_name}}</td>

封装在一个指令中是一个更好的解决方案,但是,如果你需要看到它工作,那么我认为这是可以的 – 现在.如果这对你有用,请告诉我.

– 担

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读