繁体   English   中英

获取价值输入表格

[英]Get value input form

我想在console.log中检索显示的密码值类型。 我使用带有ng-model =“ passwd”的html表单来检索值。 然后,我使用带有$ scope.passwd = null的控制器; 检索输入字段。 目前,$ scope.passwd在Google chrome => Console中仍然为null

'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> 

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

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

您正在使用ng-click="startSmartconfig()" ,除了在控制器中传递任何内容外,都使用了$scope.startSmartconfig = function(passwd){因此此代码无效。

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

我不知道$window.cordova问题,但是我观察到的是您没有在html中的ng-click="startSmartconfig()"中传递passwd ,并且正在将passwd分配给$scope.passwd ,它将是未定义的。

并且无需在函数中传递passwd 您可以直接在$scope.passwd获取更新的值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM