热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ionic/AngularJS和一个简单的登录屏幕-Ionic/AngularJSandasimpleloginscreen

ImtryingoutIonicAngularJSforthefirsttime,andarecreatingasimpleloginwithtokensentv

I'm trying out Ionic/AngularJS for the first time, and are creating a simple login with token sent via mobile.

我第一次尝试了Ionic/AngularJS,并创建了一个简单的通过mobile发送的令牌登录。

I've got an input field for phone number and an input field for the token/code.

我有电话号码的输入字段和令牌/代码的输入字段。

At first only the phone number input field is visible, but when a user request a code, the code input field should become visible. As soon as a user has entered a 4 digit code, the button should change from "Get code" to "Log in" and call the function with 2 parameters.

首先,只有电话号码输入字段是可见的,但是当用户请求代码时,代码输入字段应该是可见的。当用户输入4位数字代码时,按钮应该从“Get code”改为“Log in”,并调用带有两个参数的函数。

This is my code so far: http://codepen.io/anon/pen/PZOOBz

这是我目前的代码:http://codepen.io/anon/pen/PZOOBz

I'm kind of stuck with changing the button text and behavior after a user has entered the phone number.

在用户输入了电话号码后,我不得不更改按钮文本和行为。

HTML:

HTML:


  
    
    
    
    
    
  
  
    
    
    
  

JS:

JS:

angular.module('Hello', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('signin', {
      url: '/signin',
      templateUrl: 'templates/signin.html',
      controller: 'SignInCtrl'
    })
    .state('home', {
      url: '/home',
      templateUrl: 'templates/home.html'
    });

    $urlRouterProvider.otherwise('/signin');
})

.controller('SignInCtrl', function($scope, $state) {
  $scope.signIn = function(phoneNumber, code) {
    console.log('Sign In Phone Number', phoneNumber);
    console.log('Sign In Code', code);
    $state.go('home');
  };

  $scope.signIn = function(phoneNumber) {
    console.log('Sign In Phone Number', phoneNumber);
  };
});

3 个解决方案

#1


0  

You can use an expression like {{buttonText}}.

可以使用{{{{{buttonText}}这样的表达式。

JS:

JS:

angular.controller('SignInCtrl', function($scope) {
     $scope.buttOnText= 'bla';

     $scope.changeText = function() {
           $scope.buttOnText= 'foo';
     }
});

HTML:

HTML:


Not first the button has bla as Text and after a click the text changes from bla to foo and will be rerendered.

首先,按钮将bla作为文本,单击后,文本将从bla更改为foo,并将重新运行。

#2


0  

I don't understand your logic so much.

我不太理解你的逻辑。

But your purpose is to change the button text when the phoneNumber's length is equal to 4 or more than that, right?

但是你的目的是当phoneNumber的长度等于或大于4时改变按钮文本,对吧?

so, your button code can write as:

因此,您的按钮代码可以写成:


And, I have an advice.

我有个建议。

In your controller, just write signIn function as this:

在你的控制器中,只要像这样写登录函数:

$scope.signIn = function(phoneNumber, code) {
    if ( typeof code === 'undefined' ) {
        console.log('Sign In Phone Number', phoneNumber);
    }
    else {
        console.log('Sign In Phone Number', phoneNumber);
        console.log('Sign In Code', code);
        $state.go('home');
    }
};

#3


0  

You can use the following,

你可以用以下方法,

In HTML,

在HTML中,

  



In controller,

在控制器中,

$scope.ShowGetCode=true;
$scope.calPhOno=function(no){
  if(no.length == 4){
    $scope.editing=true;
  }else{
    $scope.editing=false;
  }
}

$scope.Calgetcode=function(){
 $scope.editing=false;
 $scope.ShowGetCode=false;
 $scope.GetCode=true;
 $scope.ShowSignIn=true;
}

$scope.calSignIn=function(no){
 if(no.length == 4){
    $scope.editing=true;
  }else{
    $scope.editing=false;
  }
}

$scope.signIn=function(){
 $location.path("/homepage");
}

Refer my codpen :

请参考我的codpen:

http://codepen.io/mohanapriya/pen/NrrwQN?editors=1000

http://codepen.io/mohanapriya/pen/NrrwQN?editors=1000


推荐阅读
author-avatar
alilx
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有