【问题标题】:How to send value of ng-repeat to other class in HTML using Agrular js如何使用 Agrular js 将 ng-repeat 的值发送到 HTML 中的其他类
【发布时间】:2018-04-16 09:53:03
【问题描述】:

我想按照以下代码 sn-ps 向 java-script 类发送值,

 <div  class="GaugeMeter" 
        data-percent="50"
        data-append=" psi"
        data-size="130" 
        data-theme="#33ccff"
        data-back="rgba(0, 0, 0, 0.5)"
        data-animate_gauge_colors="1"
        data-animate_text_colors="1"
        data-width="15"
        data-label="56 °" 
        data-style="Arch" 
        data-label_color="#FFF"> 
     </div>

我正在使用 Angularjs 和 HTML 来发送和显示值

<p ng-repeat="v in infoDetails">
    <div  class="GaugeMeter" 
        data-percent="{{v.pressure}}"
        data-append=" psi"
        data-size="130" 
        data-theme="#33ccff"
        data-back="rgba(0, 0, 0, 0.5)"
        data-animate_gauge_colors="1"
        data-animate_text_colors="1"
        data-width="15"
        data-label="56 °" 
        data-style="Arch" 
        data-label_color="#FFF"> 
    </div> 
</p>  

但我无法在其他 div 中发送压力值。所以我怎么能做到这一点。

提前谢谢你!!

【问题讨论】:

  • send parameter of pressure in other div 是什么意思?你想把它发送到哪个div?还是你想使用类似于ng-attr-id 的东西??
  • 我想将值从 ng_repeat 数组发送到 data-percent .. 按照上面的代码 sn-ps
  • 检查我的答案。如果您需要更多帮助,请使用您希望在代码中实现的“js”逻辑更新您的问题。我可以尝试帮助您将其移至directive

标签: javascript html angularjs angularjs-ng-repeat


【解决方案1】:

我认为除非您以 angularJS 方式进行,否则您要实现的目标将是错误的。

原因是,您试图将值传递给与 AngularJS 的 digest 循环不同步的某个属性。发生的情况是 html 已呈现,但 {{ exression}} 尚未评估和更新。它不知道角度 digest 循环

我建议您使用directives 并处理该场景。将这些值传递给指令并相应地编写javascript 代码

【讨论】:

  • @NitinKarande:酷。如果它适合您,请将其标记为答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多