从角的JS调用http.get NG-点击不工作的动态插入HTML得到 [英] ng-click not working for dynamically inserted html got from the http.get call in angular js

查看:178
本文介绍了从角的JS调用http.get NG-点击不工作的动态插入HTML得到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用了棱角分明的js我的PHP项目。我使用ngclick锚链接,是这样的。

Hi I am using angular js for my php project. I am using ngclick for anchor link which is like this

<a href="http://localhost/mediaads/signup" ng-click="showregister($event)">Don't have an account? Create One</a>    

当点击链接我也可以调用方法showregister的控制器,并通过调用替换HTML HTTP GET方法。

when clicks on the link i will call method showregister in controller and replace the html by calling http get method.

$http.get(baseUrl+'signup').success(function(res){$(elem).replaceWith(res);})    

RES是HTML数据,并再次有NG点击HTML

res is the html data and again it has ng click in the html

动态HTML得到的数据再次纳克点击在其中。这些纳克点击不工作

Dynamically got html data has again ng clicks in them. Those ng clicks are not working

谁能告诉我如何使ngclick工作动态元素。

Can anyone tell me how to make ngclick work for dynamic elements.

推荐答案

这是动态添加像这样的HTML必须手动示波器相连。

HTML that is added dynamically like this must manually be linked with a scope.

要做到这一点注入,并使用 $编译服务:

To do this inject and use the $compile service:

$http.get(baseUrl + 'signup').success(function(res) {
  $(elem).replaceWith($compile(res)($scope));
});

演示: http://plnkr.co/编辑/ E0neYHsVnmHKn7goLqL4?p = preVIEW

这篇关于从角的JS调用http.get NG-点击不工作的动态插入HTML得到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆