【问题标题】:how could i get event fire when ng-clickng-click 时如何触发事件
【发布时间】:2014-08-06 11:50:08
【问题描述】:

我正在使用ng-bind-html 模板添加带有ng-click 的锚标记,但ng-click 没有触发...我需要一个触发该功能的解决方案。

我的模板

$scope.res =$scope.res+'<a href="javascript:void(o)" ng-click="fullfillmentCenter('+row.orderId+')"  title="Send to fullfilment" class="">Send to CA Fullfilment</a>';

我的绑定 html

<div class="ngCellText" id="div_fullfilment_{{row.getProperty(\'orderId\')}}" ng-bind-html="fullfillment(row.entity)"></div>';

ng 函数调用

$scope.fullfillmentCenter = function(orderId){
alert(orderId);
};

【问题讨论】:

    标签: angularjs ng-bind-html ng-bind


    【解决方案1】:

    您需要使用 $compile 服务编译您的 html,以便任何 AngularJS 绑定工作。由于 $compile 需要 html 元素进行编译,因此最好创建一个指令。请参阅此 SO 帖子Compiling dynamic HTML strings from database

    如果模板已修复,另一个可行的替代方法是使用ng-include 并包含您的模板。使用ng-include 编译会自动进行。

    您可以将模板定义为

    <script type='text\ng-template' id='content'>
       <a href="javascript:void(o)" ng-click="fullfillmentCenter(row.orderId)"  title="Send to fullfilment" class="">Send to CA Fullfilment</a>
    </script>
    

    然后在任何地方使用 ng-include 包含它 &lt;div ng-include="content"&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 2015-12-06
      • 1970-01-01
      相关资源
      最近更新 更多