【问题标题】:AngularJS redirecting to another ng-app moduleAngularJS 重定向到另一个 ng-app 模块
【发布时间】:2014-01-03 06:43:00
【问题描述】:

这里是 AngularJS 的新手。

我使用 Yeoman、grunt 和 bower 创建了一个 AngularJS 应用程序。

索引页面包含一些样式以及 ng-app 和 ng-view。

index.html

<html>
  <head>
      <!-- CSS Imports -->
   </head>
   <body ng-app="MyApp1">
      <div>
          //Some divs here to  have some styles

          <div ng-view></div>
      </div>
    </body>
    <!--importing AgularJS, app.js, controller JS files -->
</html>

app.js

'use strict';

angular.module('MyApp1', [])
  .config(function ($routeProvider,$locationProvider) {
    $routeProvider
        .when('/', {
          redirectTo: '/main'
        })
      .when('/invoice', {
        templateUrl: 'views/invoice.html',
        controller: 'UploadController'
      })
      .when('/main', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .when('/login', {
            templateUrl: 'views/login.html',
          })
      .otherwise({
        redirectTo: '/main'
      });
//    $locationProvider.html5Mode(true);
  });

    angular.module('LoginApp', [])
    .config(function ($routeProvider,$locationProvider) {

    });

索引页有ng-view,它将显示invoice.html 或main.html。默认为main.htmlma​​in.html

<div class="hero-unit">
  <a ng-href="views/login.html" target="_self">Login</a>
  <br>
  <a ng-href="#invoice">New Document</a>

</div>

好的。在这个main.html 中,我有两个链接。其次是发票链接。这无论如何都会显示在 index.html ng-view 中。控制器UploadController 属于MyApp1 模块。它有单独的 JS 文件。它工作正常。

第一个链接指向另一个 HTML 页面。它的 login.html。它还有另一个名为 LoginAppng-app。这两个模块都是独立的,位于不同的页面中。

当我点击第一个链接时,它会转到 login.html。但在 URL 中,它显示为 http://localhost:9000/views/login.html。但我希望它像 http://localhost:9000/login 一样显示,就像其他 main.html (http://localhost:9000/#/main) 一样。当我编辑&lt;a ng-href="#login"&gt;Login&lt;/a&gt; 之类的链接时,它不起作用。

而且$locationProvider.html5Mode(true); 也不适合我。

【问题讨论】:

  • 只是将ng-href="views/login.html" 更改为ng-href="/login" 不起作用?

标签: javascript jquery html angularjs route-provider


【解决方案1】:

将 login.html 放到与 index.html 相同的文件夹中。

我认为不可能路由到另一个模块。但是这个 login.html 的路由规则不适用于(外部)页面。

【讨论】:

  • 你知道其他方法吗?
  • 把 login.html 放到 index.html 一样的文件夹下,让外部链接 登录跨度>
  • 网址仍然没有改变
  • 嗨我如何在第二个模块中添加路由规则?当我添加.when('/loginr', { templateUrl: 'views/login.html' }); inside LoginApp 模块时,我得到Uncaught Error: No module: LoginApp
  • mc:没有路由规则,只有登录
猜你喜欢
  • 1970-01-01
  • 2014-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-07
  • 2013-08-23
  • 1970-01-01
  • 2019-10-25
相关资源
最近更新 更多