javascript - AngularJS - $routeProvider 和 data-ng-view 的问题

标签 javascript html angularjs routes ngroute

我有以下 html 页面,

  1. index.html - 有 ng-view
  2. 欢迎.html
  3. app.html - 有许多子页面。所以需要使用ng-view

我最初的$routeProvider是,

$routeProvider
    .when('/', {
        redirectTo: '/welcome'
    })

    .when('/welcome',{
        templateUrl: 'views/welcome.html',
        controller: welcomeCtrl
    })

    .when('/app',{
        templateUrl: 'app.html',
        controller: mainCtrl
    })

    .otherwise({
        redirectTo: '/welcome',
    });

现在 app.html 中有多个子页面。如何为此添加路由?

我对 AngularJS 比较陌生。我尝试在 app.html 中添加 ng-view 并尝试在同一个 $routeProvider 中定义路由,但是当我这样做时,我收到错误,超过最大调用堆栈 错误,并且我的浏览器内存像任何东西一样增加,然后挂起。我严重缺少一些基本的东西

提前感谢您的帮助。

最佳答案

我建议您使用angular ui-router :

AngularUI Router is a routing framework for AngularJS, which allows you to organize the parts of your interface into a state machine. Unlike the $route service in the Angular ngRoute module, which is organized around URL routes, UI-Router is organized around states, which may optionally have routes, as well as other behavior, attached.

关于javascript - AngularJS - $routeProvider 和 data-ng-view 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28499177/

相关文章:

jquery - 在浏览器窗口的中心覆盖 DIV

angularjs $http post 无法正常工作

javascript - 覆盖 Javascript 中的默认函数?

javascript - 在 jQuery 函数内调用函数

javascript - 语法错误 : Unexpected Token, discord bot 编码

javascript - Angular ng-Model不同的观点和值(value)

javascript - 在不刷新的情况下监听事件和更新页面

javascript - Bootstrap日期选择器: hide calendar on enter key press

javascript - <object> 由从 $(document).ready 调用的函数创建,未呈现

javascript - 如何以全高和可变宽度居中图像