2015-10-16 86 views
0

路由在我的应用程序的设置如下:路由不离子应用工作

$stateProvider 
    .state('app', { 
    url: '', 
    abstract: true, 
    template: '<ion-nav-view></ion-nav-view>' 
    }); 

    $stateProvider 
    .state('app.todos', { 
    url: '/home', 
    views: { 
     todos: { 
     templateUrl: 'home.html', 
     controller: 'TodosCtrl' 
     } 
    } 
    }); 

    $stateProvider 
    .state('app.help', { 
    url: '/help', 
    views: { 
     help: { 
     templateUrl: 'help.html'  
     } 
    } 
    }); 

$urlRouterProvider.otherwise('/home'); 

//index.html

<body> 
    <ion-nav-bar class="bar-positive"> </ion-nav-bar> 

    <ion-tabs class="tabs-positive"> 

    <ion-tab icon="ion-checkmark" ui-sref="app.todos"> 
     <ion-nav-view name="todos"></ion-nav-view> 
    </ion-tab> 

    <ion-tab icon="ion-help" ui-sref="app.help"> 
     <ion-nav-view name="help"></ion-nav-view> 
    </ion-tab> 


    </ion-tabs> 


    <script type="text/ng-template" id="home.html"> 
    <ion-view title="Todos"> 
     <ion-content padding="true"> 
     <h2>Home Page</h2> 
     <p>Here's the main route for the app.</p> 
     </ion-content> 
    </ion-view> 
    </script> 

    <script type="text/ng-template" id="help.html"> 
    <ion-view title="Help"> 
    <ion-content padding="true"> 
     <h2>Using the app</h2> 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p> 
    </ion-content> 
    </ion-view> 
</script> 

</body> 

在应用程序的开始,我希望国家app.todos到变为活动并显示相应的模板。

这没有发生。

Plnkr可在这里: http://plnkr.co/edit/LDNLHx?p=preview

+0

如何链接到这条路线?我以为我注意到了一个无效的锚标签...你能告诉我们链接到朋友页面的代码吗? – Makoto

+0

不确定您是否打开了正确的plnkr – runtimeZero

+0

继续并在此发布您的tabs.html文件,我会告诉你我的意思。 – Makoto

回答

0

看看这个codepen http://codepen.io/aaronksaunders/pen/wKMEYP?editors=101

我感动的标签模板出一个HTML文件和结构是如何,我用它来使用标签,似乎工作正常。

<script type="text/ng-template" id="tabs.html"> 
    <ion-tabs class="tabs-positive"> 
     <ion-tab icon="ion-checkmark" ui-sref="app.todos"> 
     <ion-nav-view name="todos"></ion-nav-view> 
     </ion-tab> 

     <ion-tab icon="ion-help" ui-sref="app.help"> 
     <ion-nav-view name="help"></ion-nav-view> 
     </ion-tab> 
    </ion-tabs> 
    </script> 

我还调整了您的抽象状态来处理新的结构的报价下意见

.state('app', { 
    url: "/app", 
    abstract: true, 
    templateUrl: "tabs.html" 
    }) 
0

认沽名。

观点:{ '待办事项':{ templateUrl: 'home.html做为', 控制器: 'TodosCtrl' }}