AngularJS嵌套应用 [英] AngularJS nested app

查看:201
本文介绍了AngularJS嵌套应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要窝另一应用程序内的应用程序,我在寻找如何做到这一点很好的做法。

I need to nest an app inside another app, I am looking for good practice on how to do that.

我有管理的身份验证的用户控制面板中的userApp。
因此,对于非认证用户的结构看起来是这样的。

I have a "userApp" that manages a control panel for authenticated user. So the structure for non-authenticated users looks like this.

<html>
  <body>
    <nav>
      Login
    </nav>
    <div>
      ....
    </div>
  </body>
</html>

登录是由PHP管理,因此当用户登录自己被重定向到控制面板和结构看起来是这样的。

The login is managed by PHP, so when the user is logged he's being redirected to the control panel and the structure looks like this.

<html>
  <body>
    <nav>
      User
    </nav>
    <div ng-app="userApp">
      <div ng-view="">...</div>
      ....
    </div>
  </body>
</html>

所以,现在我需要定义在这一个顶部的主应用程序,这是由认证和非认证用户共享,结构将看起来像这样。

So, now I need to define a main app on top of this one, that's shared by authenticated and non-authenticated users, the structure will looks like this.

<html>
  <body ng-app="mainApp">
    <nav>
      User
    </nav>
    <div ng-app="userApp">
      <div ng-view="">...</div>
      ....
    </div>
  </body>
</html>

这两个应用程序并不需要共享什么,这只是我需要管理认证和非认证用户之间的共同数据的主要的应用程序。例如可管理的导航栏,侧边栏,不同的Ajax调用,但如果用户进行身份验证或没有不关心(这部分是真实的,则userApp可以设置能够在userApp外部读取,并可以通过mainApp管理localStorage的变量)。该userApp有航线,mainApp没有。

The two apps doesn't need to share anything, it's just that I need a main app that manages common data between authenticated and non-authenticated users. For example can manage the navbar, a sidebar, different ajax calls but does not care if a user is authenticated or not (this is partially true, the userApp can set localStorage variables that can be read outside the userApp and can be managed by the mainApp). The userApp has routes, the mainApp don't.

我并没有尝试过,但我pretty确保它要打破,我期待为如何达到同样的效果最佳实践(我不想把事情弄糟code和两个月后,发现这是一个弗兰肯斯坦....)

I did not tried yet but I'm pretty sure it's going to break and I am looking for best practice on how to achieve the same result (I don't want to mess up the code and after two months find out that this is a frankenstein....)

有何建议?这是不是可以实现的,或我需要重新考虑结构,避免mainApp(比方说,我可以使用jQuery做同样的事情...)。我只是不希望松散的userApp路由,如果可能,我不想改变这一个东西,因为它是被单独维护,它的准备和测试,因为它是。

Any advice? Is this something achievable or I need to rethink the structure and avoid the mainApp (let's say, I can use jQuery to do the same things...). I just don't want to loose the routing in the userApp and if possible I don't want to change anything in this one as it's being maintained separately, it's ready and tested as it is.

感谢

貌似答案是否定的
AngularJS应用程序不能相互嵌套。

所以我的问题是,它是可以移动userApp在体内的水平,只使用路由当用户进行身份验证,只有在控制面板?

So my question is, is it possible to move the userApp at the body level and use routing only when the user is authenticated and only in the control panel?

示例

/ 首页

/用户#/ 控制面板

/用户#/帐户角路线

/一些-网址没有棱角的路线

/一些-URL /一些页没有棱角的路线

推荐答案

在我看来,你应该重新审视自己的结构,例如,您可以创建嵌套控制器和管理身份验证服务的应用程序。

In my opinion you should rethink your structure and, for example, you could create an app with nested controllers and a service to manage the authentication.

我发现关于嵌套应用程序出了点问题,似乎有人能够做什么,但可能不是你的情况。反正一起来看看:

I found some question about nested apps, seems that someone was able to do something but probably is not your case. Anyway take a look:

<一个href=\"http://stackoverflow.com/questions/22548610/can-i-use-one-ng-app-inside-another-one-in-angularjs\">Can我用在另一个一一NG-应用在AngularJS

<一个href=\"http://stackoverflow.com/questions/18184617/angularjs-how-to-nest-applications-within-an-angular-app\">AngularJS:如何鸟巢应用的角度应用内

这篇关于AngularJS嵌套应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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