2016-03-29 77 views
0
**html file** 
<body ng-app="starter"> 
<ion-pane> 
<ion-header-bar class="bar-stable"> 
<div ng-controller="loginCtrl"> 
<h3>Login</h3> 
<form> 
<label>Username:</label><input type="text" ng-model="username" /><br><br> 
<label>Password:</label><input type="password" ng-model="password"><br> 
<button type="submit" ng-click="submit()">login</button> 
</form> 
</div> 
</ion-header-bar> 
<ion-content> 
</ion-content> 
</ion-pane> 
<script type="text/javascript"> 
var app = angular.module('starter', ['ionic']); 
app.controller('loginCtrl', function($scope, $location, $http, $state){ 
$scope.submit=function() 
{ 
var user=$scope.username; 
var pass=$scope.password; 
if($scope.username=="admin" && $scope.password=="1234") 
{ 
$location.path('templates/first'); 
} 

别的 { /警报( “错误”);/ $ location.path('/ second'); } }
}); location.path是用于导航页面的正确语法,但它在url栏中工作,但不在页面导航中。angularjs和离子框架和的NodeJS

**app.js file** 
angular.module('starter', ['ionic']) 
.config(function($stateProvider, $urlRouterProvider) { 
$stateProvider 
.state('/', { 
url: '/', 
abstract: true, 
templateUrl: 'index.html' 
}) 
.state('/first', { 
url: '/first', 
abstract: true, 
templateUrl: 'templates/first.html' 
}) 
.state('/second', { 
url: '/second', 
abstract: true, 
templateUrl: 'templates/second.html'(these first and second html pages are given in templates folder in www folder of the project. 
}); 
$urlRouterProvider.otherwise({ redirectTo: '/login' }); 
}); 

点击提交按钮后,页面不会导航到first.html页面。

+0

$ location.path('templates/first');你确定这条路吗?怎么样/首先,而不是模板/第一? –

+0

请详细说明您的问题。 –

+0

尝试** $ state.go('stateName')** –

回答

0

这些州是抽象的。删除抽象,因为它们不是抽象状态。

.state('first', { 
url: '/first', 
abstract: true, 
templateUrl: 'templates/first.html' 
}) 

.state('first', { 
url: '/first', 
templateUrl: 'templates/first.html' 
}) 

看到这一点: Why give an "abstract: true" state a url? https://github.com/angular-ui/ui-router/wiki/Nested-States-&-Nested-Views#abstract-states

+0

它仍然不能正常工作 –

+0

您需要在您的index.html里面使用ui-view –

+0

您可以给任何一个单一按钮进入ui-view的例子点击下一页。并不意味着离子选项卡。离子选项卡非常混乱。只需按一下按钮并导航到一个页面即可。而已。预先感谢,如果你有关这个Asim K T的帮助.... :) –

0
  • 您正在使用错误的$location.path('templates/first');,因为在你的模块定义你已经宣布它为url: '/first'。请使用$state.go('/first')导航到您的页面。

  • 也从firstsecond页面定义中删除abstract属性。

  • $urlRouterProvider.otherwise({ redirectTo: '/login' });因为没有此类网址login

希望它能帮助,这也是错误的了。

+0

first.html页面位于模板文件夹中。所以我保持$ location.path('模板/第一');实际上,在网址栏中,它会去那个特定的地方,但页面不会。它仍然在登录页面本身,也是我试图$ state.go它给出了一个错误,因为“无法解析”/第一'从状态''“我认为一些ion-nav-view指令可能对导航有用。你可以谈谈吗?因为我的first.html页面只包含一行登录成功。 –

+0

首先'$ location.path()'不用于模板发现。它将网址放在浏览器上进行定位。例如'$ location.path('templates/first')'会在url属性的模块定义中找到**'templates/first'**。 其次尝试从'/ first'到'first'的状态名称chaging我认为特殊字符在这里引起问题,如果一切都很好。 –