对已加载的无棱角的网页激活角JS [英] Activating Angular JS on an already loaded non-Angular webpage

查看:130
本文介绍了对已加载的无棱角的网页激活角JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式来加载JS角不是页面加载,但后来,在需要的时候。

I'm looking for a way to load Angular JS not on page load, but later on, when needed.

我的用例是pre-现有的Web应用程序,使用老派的jQuery和Ajax显示在页面上更换不同的模块。这是前角JS倍。

My use case is a pre-existing web app, that uses old-school jQuery and Ajax to show and replace various blocks on the page. This is from before Angular JS times.

现在,我们需要发展这个页面,我们要使用的角度上JS一个较为复杂的部分,因为它本来相当复杂,开发所需的功能。在不改变应用程序太多了,我们希望包括角只是在页面上这一小部分(附加一些复杂的规则形式:显示,隐藏,循环等)

Now, we need to develop a somewhat more complex part on this page, for which we want to use Angular JS, because it would otherwise get quite complex to develop the desired functionality. Without changing the app too much, we want to include Angular just for this small part on the page (a form with some complex rules attached: show, hide, loop, etc...)

我的问题是:

1)如何启动角JS需求?该页面不具有NG-应用,NG-controller或角JS最初加载。在需要的时候,我可以添加使用jQuery这些属性和运行一些code启动它,但这并不没有缝页面加载事件工作。

1) How to start Angular JS "on demand"? The page does not have the "ng-app", "ng-controller" or Angular JS loaded initially. I can add these attributes using jQuery when needed and run some code to start it, but this does not seam to work without the page load event.

2)角应JS虽然HTML片段,在需要的时候,应用程序将包括启动。这符合老斯库尔方式应用程序的工作,所以我们不希望改变这种状况。

2) Angular JS should be started though a HTML fragment which the app will include when needed. This fits the old skool way the app works, so we don't want to change this.

3)现有的应用程序使用原型JS和jQuery中没有冲突模式。当有角JS进入图片需要prevent冲突特步?

3) The existing app uses Prototype JS and jQuery in no conflict mode. Are special steps needed to prevent conflicts when Angular JS enters the picture?

先谢谢了。

推荐答案

你就可以开始用角

  angular.bootstrap(document, ['myApp']);
  $('html').addClass('ng-app: myApp');

这篇关于对已加载的无棱角的网页激活角JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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