简体   繁体   English

生成的HTML上的Angular指令

[英]Angular directive on generated HTML

I'm working on an existing website that currently use jQuery and PHP. 我正在一个当前使用jQuery和PHP的现有网站上工作。 On a page, HTML code is generated by jQuery AJAX calling PHP code. 在页面上,HTML代码是由jQuery AJAX调用PHP代码生成的。 How would one add angular directives to this HTML code ? 如何将角度指令添加到此HTML代码?

For example, the PHP code generates : 例如,PHP代码生成:

<div class="testDiv">click me</div>

I would like : 我想要 :

<div class="testDiv" ng-click="angularFunction()">click me</div>

As I understand it, angular directives need to be compiled using $compile. 据我了解,角度指令需要使用$ compile进行编译。 Is there a function like jQuery's "on" function I can use ? 我可以使用类似jQuery的“ on”功能的功能吗?

Thanks 谢谢

In that case, yes use $compile. 在这种情况下,请使用$ compile。 If you want to learn angular forget the way you do things in jquery. 如果您想学习角度学习,请不要在jquery中做事。 If you try to mimic jquery that most likely will be wrong. 如果您尝试模仿jquery,则极有可能是错误的。 That's why they call it the angular way. 这就是为什么他们称其为有角度的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM