我可以在 AngularJS 中的另一个应用程序中使用一个 ng-app [英] Can I use one ng-app inside another one in AngularJS

查看:28
本文介绍了我可以在 AngularJS 中的另一个应用程序中使用一个 ng-app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 ng-app喜欢;

<div ng-app="app1" >表情<div ng-app="app2">多一些表达

有什么办法让它工作吗?当我制作嵌套的 ng-app 时它不起作用

我知道我可以使用两个不同的控制器,但我不想使用两个控制器---- 编辑-----

事情是;

 angular.module('AppName', ['角度旋转木马'])

所以我需要以某种方式将此 ng-app 更改为指令

解决方案

从 AngularJS 文档来看,答案是否定的

<块引用>

http://docs.angularjs.org/api/ng/directive/ngApp

AngularJS 应用程序不能相互嵌套.

如果没有嵌套,那也没关系,已经有人问过这个问题了,参考这里:一个页面内的多个AngularJS ng-app和 AnguarJS 文档

<块引用>

http://docs.angularjs.org/api/ng/directive/ngApp

每个 HTML 文档只能自动引导一个 AngularJS 应用程序.在文档中找到的第一个 ngApp 将用于定义根元素以作为应用程序自动引导.要在 HTML 文档中运行多个应用程序,您必须使用 angular.bootstrap 手动引导它们.

I have two ng-app like ;

<div ng-app="app1" >
    somexpression   
    <div ng-app="app2">
        some more expression
    </div>
</div>

is there any way to make it work? when I make a nested ng-app it doesn't work

I know that I can use two different controller but I don't want to use two controllers ---- EDIT -----

The thing is;

 angular.module('AppName', [
            'angular-carousel'
        ])

SO I need somehow to change this ng-app to directive

解决方案

From the AngularJS document, the answer is no

http://docs.angularjs.org/api/ng/directive/ngApp

AngularJS applications cannot be nested within each other.

And if not nested, then it's OK, someone already asked this question, refer here:AngularJS Multiple ng-app within a page and the AnguarJS document

http://docs.angularjs.org/api/ng/directive/ngApp

Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap instead.

这篇关于我可以在 AngularJS 中的另一个应用程序中使用一个 ng-app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆