简体   繁体   English

离子 - 同一页面中的多个视图

[英]Ionic - Multiple view in same page

I am kind of a noob in Ionic and I need help / guidelines to build something that sounds easy. 我是Ionic中的一个菜鸟,我需要帮助/指导来构建听起来很容易的东西。 I want to have a single page composed of multiple content, the idea is to have multiple views in the same page each of them being linked to a specific controller. 我希望有一个由多个内容组成的单个页面,其想法是在同一页面中有多个视图,每个视图都链接到一个特定的控制器。

Here is my code: 这是我的代码:

index.html content: index.html内容:

   <ion-pane>
     <ion-nav-view></ion-nav-view>

     <ion-view ng-controller="FirstController">
       <ion-content>
       </ion-content>
     </ion-view>

     <ion-view ng-controller="ScdController">
       <ion-content>
       </ion-content>
     </ion-view>
  </ion-pane>

In my app.js: 在我的app.js中:

 angular.module('app', [])
 .controller('FirstController', function($scope) {
 })

 .controller('ScdController', function($scope) {
 });

In my config.routes.js: 在我的config.routes.js中:

angular.module('app')
.config(configure);

function configure($stateProvider){
  $stateProvider
    .state('first', {
      url: '/',
      templateUrl: 'templates/first.html',
      controller: 'FirstController'
    })
   .state('second', {
      url: '/',
      templateUrl: 'templates/second.html',
      controller: 'ScdController'
   });
 }

Templates are very simple: 模板很简单:

first.html: first.html:

<div>first</div>

second.html: second.html:

<div>Second</div>

Right now nothing is displayed. 现在没有显示任何内容。

What do you guys think? 你们有什么感想?

Thanks for your help! 谢谢你的帮助!

Your requirement is multiple named views. 您的要求是多个命名视图。 Following document is useful to implement multiple views in a single page https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views 以下文档对于在单个页面中实现多个视图很有用https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views

Example code: 示例代码:

HTML: HTML:

<ion-view title="">
   <ion-content scroll="true">
     <div ui-view="first"></div>
     <div ui-view="second"></div>
   </ion-content>
</ion-view>

JS: JS:

angular.module('app')
 .config(function($stateProvider) {
   $stateProvider
    .state({
       name : 'multiple-views'
       views: {
        'first': {
           url: '/',
           templateUrl: 'templates/first.html',
           controller: 'FirstController'
         },
        'second': {
           url: '/',
           templateUrl: 'templates/second.html',
           controller: 'ScdController'
         }
       }
    });

Working example link: http://plnkr.co/edit/kZZ4KikwLITOxR5IGltr?p=preview 工作示例链接: http//plnkr.co/edit/kZZ4KikwLITOxR5IGltr?p = preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM