gpt4 book ai didi

javascript - $scope 没有获取 ng-model html 值

转载 作者:行者123 更新时间:2023-12-02 14:14:54 24 4
gpt4 key购买 nike

这是我的 Controller 文件

'use strict';

cms.controller('homeController', function($scope, $http, $window) {



$scope.registerClinic = function () {
var dataParam={
"primaryEmailId": $scope.data1.emai
}
console.log(angular.toJson(dataParam));
$http({
url: "/cms/sign-up",
method: "POST",
headers :{'Content-Type': 'application/json','Accept': 'application/json' },
data: dataParam
})

.success(function(response) {
console.log(angular.toJson(response));


});
};






});

这是我的 Html 文件在我的 html 文件中有 ng-model="data1.emai"值我想通过 Controller 中的表单解析它,但它没有发生

<body>

<div class="modal-dialog" style="background: rgb(255, 255, 255);">
<div class="modal-body login metrial">


<div class="modal-body login metrial">



<div class="col-sm-6">
<h4 class="modal-title">Sign up</h4>

<form id="loginform2" ng-submit="registerClinic()" name="loginform2" novalidate>
<div class="form-group">
<input name="email" placeholder="Email ID" ng-class="{'invalid-field': loginform2.emai.$touched || loginform2.$submitted, 'valid-field': loginform2.emai.$valid}"
ng-model="data1.emai" ng-pattern="/^[a-zA-Z0-9]+[a-zA-Z0-9._]+@[a-zA-Z0-9]+\.[a-zA-Z.]{2,}$/" type="text" required>
<span ng-show="loginform2.emai.$touched && loginform2.emai.$error.pattern" class="error-geni">Invalid email</span>
<!-- <label class="field-title">Email ID</label> -->
</div>
<div class="margin-bottom-20">
<div style="width:20%" class="input-group-addon-signup">
<input value="+91" disabled="" type="text"></div>
<div class="input-group-addon-signup"><input id="mobil" ng-class="{'invalid-field': loginform2.mobil.$touched || loginform2.$submitted, 'valid-field': loginform2.mobil.$valid}" onkeypress="return isNumber(event,'mobil');" placeholder="Mobile No" type="text"
ng-minlength="10" ng-maxlength="10" name="mobil" maxlength="10" ng-model="data1.mobil" ng-pattern="/^$|^[0-9X]{10}$/" required>
<span ng-show="loginform2.mobil.$touched && loginform2.mobil.$error.pattern" class="error-geni"> Invalid Mobile Number </span> </div>
<!-- <label class="field-title">Mobile No</label>-->
</div>

<div class="form-group">
<input id="clinic" ng-model="data1.clinic" placeholder="Clinic Name" type="text">
<!-- <label class="field-title">Clinic Name</label> -->
</div>

<select class="form-group" id="subscriptionplans" ng-model="data.Subscription" value="Subscription">
<option id="optionspec">Trial Subscription</option>
<option value="0">Silver</option>
<option value="1">Gold</option>
<option value="1">Platinum</option>
</select>

<div class="form-group">
<input name="signupPassword" id="signupPassword" placeholder="Password" ng-class="{'invalid-field': loginform2.signupPassword.$touched || loginform2.$submitted, 'valid-field': loginform2.signupPassword.$valid}" ng-model="data1.signupPassword"
ng-minlength="8" ng-maxlength="20" type="password" required>
<span ng-show="loginform2.signupPassword.$touched && loginform2.signupPassword.$error.minlength || loginform2.signupPassword.$touched && loginform2.signupPassword.$error.maxlength" class="error-geni">Password must be 8-20 characters long and must have at least one uppercase character & one number and can have special characters -_/#@</span>
</div>


<!--confirm Password-->
<div class="form-group">
<input name="docPassword2" id="docPassword2" ng-class="{'invalid-field': loginform2.docPassword2.$touched || loginform2.$submitted, 'valid-field': loginform2.docPassword2.$valid}" placeholder="Confirm Password"
ng-model="data1.docPassword2"
class="gui-input" required ng-compare="loginform2.signupPassword"
ng-disabled="!loginform2.signupPassword.$valid" type="password"/>

<span ng-show="loginform2.docPassword2.$touched && loginform2.docPassword2.$error.compare1" class="error-geni">Password Mismatch </span>
</div>


<button type ="submit" class="btn pull-right" type="button">SIGN UP</button>
</form>

</div>
</div>
</div>



</body>

编辑:我尝试通过 data1.emai 访问它错误

angular.min.js:108 TypeError: Cannot read property 'emai' of undefined
at n.$scope.registerClinic (home-controller.js:37)
at fn (eval at compile (angular.min.js:212), <anonymous>:4:262)
at f (angular.min.js:252)
at n.$eval (angular.min.js:134)
at n.$apply (angular.min.js:135)
at HTMLFormElement.<anonymous> (angular.min.js:252)
at HTMLFormElement.c (angular.min.js:35)is saying

我无法理解为什么我的值没有通过 html 进入 Controller 中的 $scope

当我从输入中删除所有值时进行编辑

它正在工作..但没有找到确切的问题

最佳答案

您可以从这样的范围访问它:

"primaryEmailId": $scope.emai

在模板中以这种方式绑定(bind)它:

 ng-model="data1.emai"

您需要在范围内有 data1 对象以使其一致,例如:

"primaryEmailId": $scope.data1.emai

关于javascript - $scope 没有获取 ng-model html 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39120014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com