angularjs和离子框架和nodejs

时间:2016-03-29 09:14:41

标签: angularjs node.js ionic-framework

 **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( '/秒');     }     }
    });           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页面。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

  • 您使用了错误的$location.path('templates/first');,因为在您的模块定义中,您已将其声明为url: '/first'。而是使用$state.go('/first')导航到您的网页。

  • 同时从abstractfirst页面定义中删除second媒体资源。

  • $urlRouterProvider.otherwise({ redirectTo: '/login' });这也是错误的,因为没有login

  • 这样的网址

希望它有所帮助。