Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS多个布局页面_Angularjs_Layout_Master Pages - Fatal编程技术网

AngularJS多个布局页面

AngularJS多个布局页面,angularjs,layout,master-pages,Angularjs,Layout,Master Pages,我有一个angularjs应用程序,它有app.js(应用程序启动的主js文件),index.html文件,类似于母版页(应用于应用程序中的所有页面)。此index.html位于我的项目/应用程序的根目录中 我想在应用程序中添加2-3个具有新主控/布局页面(而不是index.html)的新页面。我想创建index2.html,它将应用于某些页面,index3.html将应用于某些页面 所有3种布局index.html、index2.html和index3.html完全独立/彼此不同 我尝试了所有

我有一个angularjs应用程序,它有app.js(应用程序启动的主js文件),index.html文件,类似于母版页(应用于应用程序中的所有页面)。此index.html位于我的项目/应用程序的根目录中

我想在应用程序中添加2-3个具有新主控/布局页面(而不是index.html)的新页面。我想创建index2.html,它将应用于某些页面,index3.html将应用于某些页面

所有3种布局index.html、index2.html和index3.html完全独立/彼此不同


我尝试了所有方法,但新页面总是将index.html作为默认布局。

我想你要找的是Angular UI Router。在这里查看:

您必须将index.html配置为“主”状态,并为其他索引文件提供嵌套视图

查看文档了解详细信息,但基本上您将设置index.html文件:

...
<body ng-app="app">
  <ui-view></ui-view>
</body>

您可能也想了解抽象状态,但我不确定您的具体要求是什么。

您可以使用多个应用程序进行多个视图
ng app=“what ever your app here”
之后,只需在某些视图中添加视图即可。

谢谢您的反馈。我以前看过这段代码,但我的要求没有什么不同。在这里,视图被添加到body标记中,这意味着所有状态的和都将是相同的。我想要完全不同的布局,完全不同。啊,我明白了。这听起来很难(也许不可能?)在客户端实现。我认为您必须使用服务器端重定向。
angular.module('app', [ui.router])
  .config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/");

    $stateProvider
      .state('home', {
        url: "/",
        templateUrl: "partials/index.html"
      })
      .state('index2View', {
        url: "/index2",
        templateUrl: "partials/index2.html"
      });
      ... add more states for your views here ...
  });