点击离子导航条上的按钮移动到新页面的所有3种方式都不起作用
All 3 ways of moving to new page on click of button in the ionic navbar dont work
理想情况下,这三种方法都应该工作。下面的代码很好地展示了这三种方法。
正确工作的CodePen Demo app
目前,这三种方法都不起作用;导航条在点击按钮时就消失了(显示空的导航条),而核心页面仍然是相同的主页面。
我不确定这是一个代码问题,离子问题或只是简单地我不应该从导航栏过渡到一个新的页面。最后一个太不合逻辑了,让人无法接受。
有没有人知道问题在哪里,请帮助我?
我的核心内容代码在index.html
<body animation="slide-left-right-ios7">
<ion-nav-bar class="bar-light nav-title-slide-ios7"></ion-nav-bar>
<ion-nav-view></ion-nav-view>
我的按钮html(注意所有3个版本都是单独测试的)
<ion-view ng-controller="NavCtrl">
<ion-nav-buttons side="left">
<button class="button button-icon ion-compose" ng-click="create('tab.newpost')"></button>
<button class="button button-icon ion-compose" ui-sref="tab.newpost"></button>
<button class="button button-icon ion-compose" href="/tab/newpost"></button>
</ion-nav-buttons>
<ion-content class>
<!-- Rest of the content body here -->
</ion-content>
</ion-view>
nav.js中的代码主要用于状态。创建方法
app.controller('NavCtrl', function ($scope, $location, $state, Post, Auth) {
$scope.post = {url: 'http://', title: ''};
$scope.create = function(stateName) {
/* $location.path('/tab/newpost'); */
$state.go(stateName); /* tried swapping stateName with 'tab.newpost' and func() */
};
});
app.js的代码(路由文件)
var app = angular.module('MyApp', ['ionic','firebase']);
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
.state('tab.posts', {
url: '/posts',
views: {
'tab-posts': {
templateUrl: 'templates/tab-posts.html',
controller: 'PostsCtrl'
}
}
})
.state('tab.newpost', {
url: '/newpost',
views: {
'tab-newpost':{
templateUrl: 'templates/tab-newpost.html',
controller: 'NewCtrl'
}
}
});
/* + other states .... */
$urlRouterProvider.otherwise('/auth/login');
});
根据代码使用的第一个方法如下
ng-click="create('tab/newpost')"
应该是
ng-click="create('tab.newpost')"
我认为你需要修改state的名称,这样你就可以在它们之间导航
var app = angular.module('MyApp', ['ionic','firebase']);
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
.state('tab.posts', {
url: '/posts',
views: {
'tab-posts': {
templateUrl: 'templates/tab-posts.html',
controller: 'PostsCtrl'
}
}
})
.state('tab.newpost', {
url: '/newpost',
views: {
'tab-posts':{ /* the same name of the above state */
templateUrl: 'templates/tab-newpost.html',
controller: 'NewCtrl'
}
}
});
/* + other states .... */
$urlRouterProvider.otherwise('/auth/login');
});
相关文章:
- 在检查单选按钮的值是否正确后,如何将其带到新页面
- 在Phonegap中重定向到新页面后,AdMob未定义
- ASP.NET MVC 3-在ajax调用后,重定向到新页面或生成页面刷新
- javascript:发送带有音频文件的POST,然后重定向到新页面
- 在onclick上动态创建新页面
- 如何将缩略图链接到新页面上的视频
- Javascript:在新页面中打开链接并运行脚本
- 视频暂停超过1分钟后重定向到新页面
- 在新页面中打开url的Javascript
- 防止 PHP 在新页面中显示结果
- 如何在边缘脚本完成后将用户定向到新页面
- 超链接单击以加载新页面并执行JavaScript
- 导航到新页面不会滚动到顶部
- 如何发布请求并将响应呈现为新页面
- 如何使用自动表单和iron路由器重定向到新页面
- 如何在发送时不打开新页面的情况下使用php/ajax发送表单
- 在RadWindow中加载新页面,然后从加载的窗体中关闭窗口
- 在IE11中,点击next或back按钮,使用intro.js打开一个新页面
- 如何使用Push.js将数据和变量传递到新页面
- 点击离子导航条上的按钮移动到新页面的所有3种方式都不起作用