【发布时间】:2016-07-16 18:11:49
【问题描述】:
**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');
}
别的
{
/alert("错误");/
$location.path('/second');
}
}
});
location.path 是导航页面的正确语法,但它在 url 栏中工作,而不是页面导航。
**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');你确定那条路吗? /first 而不是 templates/first 怎么样?
-
请详细说明您的问题。
-
试试 $state.go('stateName')
标签: angularjs node.js ionic-framework