Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将html中的值ng模型转换为javascript_Javascript_Html_Angularjs_Web_Parse Platform - Fatal编程技术网

如何将html中的值ng模型转换为javascript

如何将html中的值ng模型转换为javascript,javascript,html,angularjs,web,parse-platform,Javascript,Html,Angularjs,Web,Parse Platform,可能是个愚蠢的问题,但我有一个简单输入和密码的html表单: <li> <input type="text" placeholder="Username" ng-model="user.username" /> <a class="iconani usera"></a> </li> <li> <input type="password" placeholder="Password" ng-model="us

可能是个愚蠢的问题,但我有一个简单输入和密码的html表单:

<li>
  <input type="text" placeholder="Username" ng-model="user.username" />
  <a class="iconani usera"></a>
</li>
<li>
  <input type="password" placeholder="Password" ng-model="user.password" />
  <a class="iconani locka"></a>
</li>
我从parse.com使用这个

你能帮我吗?

在AngularJS中,你根本不需要(也不想)触摸DOM来获取数据
ng model
指令在
$scope.user
变量的属性之间创建自动双向绑定

login($scope.user.username, $scope.user.password, ...);

您根本不需要触摸表单本身。

hon2a的答案是正确的;-)我可以试着用不同的方式来解释它,因为我最近也开始使用angular。关于ng模型和控制器的角度概念,请参见

因此,所有javascript都应该在角度控制器中执行。在相应的控制器(即javascript代码)中,HTML表单中的数据使用角度指令“ng模型”绑定,而不使用其他任何东西。你的HTML部分很好,假设你在某个地方正确链接了角度的东西(我强烈建议使用Yeoman angular generator来处理这个…)。至少应该有这样的东西:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body>
<div ng-app="yourApp" ng-controller="yourController">
    <!-- your app part goes here -->
</div>

希望这有助于…

使用$scope.user.username和$scope.user。password@MatejŽvan不工作,先生:(那么您需要提供一个JSFIDLE/codepen,以显示到目前为止包含的两段代码之间的关系。angular.module('AuthApp',[])。run(['$rootScope',function($scope){$scope.scenario='logIn';$scope.currentUser=Parse.User.current();$scope.logIn=function(form){Parse.User.logIn(form.username,form.password,{success:function(User){$scope.currentUser=User;$scope.apply();},error:function(User,error){alert(error.message);};$scope.logOut=function(form){Parse.User.logOut();$scope.currentUser=null;};我已经更新了我的答案,让它更清晰(希望如此)。重要的一点是:不要在JS代码中触及表单,只需使用
$scope
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body>
<div ng-app="yourApp" ng-controller="yourController">
    <!-- your app part goes here -->
</div>
angular.module('yourApp').controller('yourController', function ($scope) {

    $scope.user = {'username': '', 'userpassword': ''};

    // And rest of your stuff goes here...
    // In your functions, just use $scope.user.username and $scope.user.userpassword. 
}