【问题标题】:Get value input form获取值输入表单
【发布时间】:2015-09-23 12:08:20
【问题描述】:

我想检索 console.log 中显示的密码值类型。 我使用带有 ng-model="passwd" 的 html 表单来检索值。 然后我使用带有 $scope.passwd=null; 的控制器。检索输入字段。 目前,谷歌浏览器中的 $scope.passwd 仍然为空 => 控制台

'use strict';

angular.module('djoro.controllers')

.controller('WifiSmartConfigCtrl', function($scope, $window, $ionicPlatform){

  $scope.passwd = null;

  $scope.startSmartconfig = function(passwd){       

        var onSuccess = function(success){

          $scope.passwd = passwd;
        };

        var onFail = function(){};

        $ionicPlatform.ready(function(){

        $window.cordova.plugins.Smartconfig.startSmartconfig(onSuccess, onFail, $scope.passwd);
            console.log('Password  = ' + $scope.passwd);
        });

  };

});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<form name="wifi_form" class="simple-form">            
    <div class="list input-fields">
       <label class="item item-input" show-hide-container>
         <span class="input-label">Password : </span>
           <input type="password" name="password" ng-model="passwd" id="passwd" show-hide-input>
       </label>         
   </div>  
</form>
<div class="startWifi">
      <button class="button button-full button-balanced" ng-click="startSmartconfig()">Start</button>
 
</div>

有人想编辑输入的值吗? 谢谢

【问题讨论】:

    标签: javascript angularjs angular-ngmodel angularjs-ng-model


    【解决方案1】:

    $scope.passwd = null; 替换为$scope.passwd = '';

    您正在使用ng-click="startSmartconfig()",除了在控制器中什么都不传递,您使用了$scope.startSmartconfig = function(passwd){,因此此代码将不起作用。

    将控制器功能设置为$scope.startSmartconfig = function(){,另一件事是angularjs是双向绑定意味着当您使用ng-model =“passwd”在输入文本中添加值时,它还将文本框值绑定到$scope.passwd。

    【讨论】:

    • chrome://inspect , console.log "password = nothing" 使用 $scope.passwd = ' ';
    【解决方案2】:

    我不知道 $window.cordova 的事情,但我观察到您没有在 html 中通过 passwd 中的 ng-click="startSmartconfig()" 并且您将 passwd 分配给 $scope.passwd,这将是未定义的。

    并且不需要在函数中传递passwd。可以直接在$scope.passwd获取更新值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-21
      • 2016-11-02
      • 2019-08-17
      • 1970-01-01
      • 2021-06-01
      • 2018-04-15
      • 2019-01-25
      • 1970-01-01
      相关资源
      最近更新 更多