2016-03-29 74 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我認爲特殊字符在這裏引起問題,如果一切都很好。 –