【问题标题】:ng-click and ng-change not workingng-click 和 ng-change 不起作用
【发布时间】:2017-06-30 23:00:24
【问题描述】:

我正在使用angular.element(document).find(id).html(code) 制作一个 html 代码,code var 中有一个 ng-click 和 ng-change。当它编写html代码时,它应该可以正常工作,分析生成的html代码:

使用 angular.element 生成的代码:

<a style="cursor:pointer" title="Atualizar" ng-click="atualizarHistorico(303456)"><i class="mdi-action-autorenew small"></i></a>

但是当我点击按钮时,它没有执行函数atualizarHistorico()

我正在生成这样的东西:

var return = '<a style="cursor:pointer" title="Atualizar" ng-click="atualizarHistorico(303456)"><i class="mdi-action-autorenew small"></i></a></div>';
angular.element(document).find('#' + id).html(return);

只有在这种情况下不起作用,带有ng-click和ng-change的html代码是由angular.element生成的。

【问题讨论】:

  • 使用 jQuery 时是否有效?

标签: javascript angularjs


【解决方案1】:

如果必须附加 HTML,则需要访问 $compile 服务。然后编译 HTML,并将其链接到具有您要执行的功能的作用域:

$scope.atualizarHistorico = function(...

var return = // HTML
var compiledAndLinked = $compile(return)($scope);
angular.element(document).find('#' + id).html(compiledAndLinked);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-22
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多