ng-click 不适用于从 angular js 中的 http.get 调用中获取的动态插入的 html [英] ng-click not working for dynamically inserted html got from the http.get call in angular js

查看:16
本文介绍了ng-click 不适用于从 angular js 中的 http.get 调用中获取的动态插入的 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的 php 项目使用 angular js.我正在使用 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 方法并通过调用 http get 方法替换 html.

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 数据,它再次在 html 中单击

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

动态获取的 html 数据中再次有 ng 次点击.那些 ng 点击不起作用

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.

为此注入并使用 $compile 服务:

To do this inject and use the $compile service:

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

演示: http://plnkr.co/edit/E0neYHsVnmHKn7goLqL4?p=预览

这篇关于ng-click 不适用于从 angular js 中的 http.get 调用中获取的动态插入的 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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