**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頁面。
$ location.path('templates/first');你確定這條路嗎?怎麼樣/首先,而不是模板/第一? –
請詳細說明您的問題。 –
嘗試** $ state.go('stateName')** –