Javascript Can';t存储使用Angular.js UI Router构建的多步骤表单的数据
我无法存储用户在我的表单上输入的数据。它是多步骤的形式,每个部分都包含在使用角度UI路由器的视图中。我已经记录了应该存储数据的对象,但它是空的Javascript Can';t存储使用Angular.js UI Router构建的多步骤表单的数据,javascript,angularjs,angular-ui-router,angularjs-factory,Javascript,Angularjs,Angular Ui Router,Angularjs Factory,我无法存储用户在我的表单上输入的数据。它是多步骤的形式,每个部分都包含在使用角度UI路由器的视图中。我已经记录了应该存储数据的对象,但它是空的 var app = angular.module("Signup", ['ui.router', "ngAnimate"]); app.config(function($stateProvider,$urlRouterProvider) { $urlRouterProvider.otherwise('/index/signup'); $stat
var app = angular.module("Signup", ['ui.router', "ngAnimate"]);
app.config(function($stateProvider,$urlRouterProvider) {
$urlRouterProvider.otherwise('/index/signup');
$stateProvider
.state('index', {
url: '/index',
templateUrl: 'index.html',
controller: 'FormCtrl'
})
.state('index.signup', {
url: '/signup',
templateUrl: 'views/signup.html',
controller: 'FormCtrl'
})
.state('index.otp', {
url: '/otp',
templateUrl: 'views/otp.html',
controller: 'FormCtrl'
})
.state('index.password', {
url: '/password',
templateUrl: 'views/password.html',
controller: 'FormCtrl'
})
.state('index.identity', {
url: '/identity',
templateUrl: 'views/identity.html',
controller: 'FormCtrl'
})
.state('index.done', {
url: '/done',
templateUrl: 'views/done.html',
controller: 'FormCtrl'
});
});
我不想用我所有的视图填充这个页面,因此我只发布一个
<div id="wrapper-signup">
<h1>Borrower Signup</h1>
<p>Register and start borrowing money online.</p>
<div class="element-wrap">
<label>NAME<br>
<div class="name-wrap">
<input type="text" ng-model="newuser.firstname" name="firstname" id="firstname" value="" placeholder="First Name">
<input type="text" ng-model="newuser.lastname" name="lastname" id="lastname" value="" placeholder="Last Name">
</div>
</label><br>
</div>
<div class="element-wrap">
<label for="email">EMAIL
<div class="email-num-wrap">
<span class="awesome-icon"><i class="fa fa-envelope-o fa-lg email-icon" aria-hidden="true"></i></span><input type="email" id="email" ng-model="newuser.email" name="email" value="" placeholder="Email ID" required>
</div>
<p class="error" style="color: red; font-size: 0.8em;" ng-show="signForm.email.$invalid && signForm.email.$dirty">Enter a valid email</p>
</label>
</div>
<div class="element-wrap">
<label>MOBILE NUMBER
<div class="email-num-wrap">
<span class="awesome-icon"><i class="fa fa-mobile fa-2x mobile-icon" aria-hidden="true"></i></span><input type="number" id="number" ng-model="newuser.number" name="mobile-number" value="" placeholder="Enter 10 digit number">
</div>
</label>
</div>
<div class="clear">
</div>
<div class="checkbox-wrap">
<input type="checkbox" class="checkbox" name="terms" value="" ng-model="tcheck" required><p class="checkbox-text">I have read and agree to the <a href="#">Privacy Policy</a>, <a href="#">Terms of Use</a> and consent to Electronic Disclosures.</p>
</div>
<div class="checkbox-wrap">
<input type="checkbox" class="checkbox" name="condiiton" value="" ng-model="ccheck" required><p class="checkbox-text">I authorize RupaiyaExchange to share my details with other Financial Institutions for credit card check and faster processing of loan.</p>
</div>
<a ui-sref='index.otp' ng-show="signForm.email.$valid && tcheck && ccheck" class="submit-signup">SIGNUP</a>
</div>
借款人登记
注册并开始在网上借钱
名称
电子邮件
输入有效的电子邮件
手机号码
我已阅读并同意,并同意电子披露
我授权RupaiyaExchange与其他金融机构分享我的详细信息,以便进行信用卡检查和更快地处理贷款
报名
每个视图重新初始化FormCtrl及其作用域,这样您将只拥有来自最后一个视图“完成”的数据,我假设最后一个视图不提供任何数据,这就是模型为空的原因,请尝试将数据存储在rootScope每个视图重新初始化FormCtrl及其作用域,这样您将只拥有来自最后一个视图“完成”的数据,我假设最后一个视图没有提供任何数据,这就是模型为空的原因,请尝试将数据存储在rootScope中。您是否将模型绑定到未定义的属性?这适合ng型号吗
尝试在工厂中设置每个属性,看看是否有帮助
例如:
您是否将模型绑定到未定义的属性?这适合ng型号吗 尝试在工厂中设置每个属性,看看是否有帮助 例如:
他们在使用服务,应该这样做。他们在使用服务,应该这样做。不。这没用。我得到了一个只有属性的对象。如果你添加一个属性,比如newuser.fruit='banana',你能在视图中打印它吗?是的,我可以在我的控制台中看到它。以及其余的空属性。您能在视图中看到它吗?{{newuser.fruit}}不,这没用。我得到了一个只有属性的对象。如果你添加一个属性,比如newuser.fruit='banana',你能在视图中打印它吗?是的,我可以在我的控制台中看到它。以及其余的空属性。您能在视图中看到它吗?例如:{{newuser.fruit}请在将其分配给
$scope.newuser
之前尝试放置console.log(dataService.newuser)
,以查看服务在该点是否具有正确的数据。请尝试放置console.log(dataService.newuser)
在将其分配到$scope.newuser
之前,查看服务在该点是否具有正确的数据。
<div id="wrapper-signup">
<h1>Borrower Signup</h1>
<p>Register and start borrowing money online.</p>
<div class="element-wrap">
<label>NAME<br>
<div class="name-wrap">
<input type="text" ng-model="newuser.firstname" name="firstname" id="firstname" value="" placeholder="First Name">
<input type="text" ng-model="newuser.lastname" name="lastname" id="lastname" value="" placeholder="Last Name">
</div>
</label><br>
</div>
<div class="element-wrap">
<label for="email">EMAIL
<div class="email-num-wrap">
<span class="awesome-icon"><i class="fa fa-envelope-o fa-lg email-icon" aria-hidden="true"></i></span><input type="email" id="email" ng-model="newuser.email" name="email" value="" placeholder="Email ID" required>
</div>
<p class="error" style="color: red; font-size: 0.8em;" ng-show="signForm.email.$invalid && signForm.email.$dirty">Enter a valid email</p>
</label>
</div>
<div class="element-wrap">
<label>MOBILE NUMBER
<div class="email-num-wrap">
<span class="awesome-icon"><i class="fa fa-mobile fa-2x mobile-icon" aria-hidden="true"></i></span><input type="number" id="number" ng-model="newuser.number" name="mobile-number" value="" placeholder="Enter 10 digit number">
</div>
</label>
</div>
<div class="clear">
</div>
<div class="checkbox-wrap">
<input type="checkbox" class="checkbox" name="terms" value="" ng-model="tcheck" required><p class="checkbox-text">I have read and agree to the <a href="#">Privacy Policy</a>, <a href="#">Terms of Use</a> and consent to Electronic Disclosures.</p>
</div>
<div class="checkbox-wrap">
<input type="checkbox" class="checkbox" name="condiiton" value="" ng-model="ccheck" required><p class="checkbox-text">I authorize RupaiyaExchange to share my details with other Financial Institutions for credit card check and faster processing of loan.</p>
</div>
<a ui-sref='index.otp' ng-show="signForm.email.$valid && tcheck && ccheck" class="submit-signup">SIGNUP</a>
</div>
app.factory('dataService', function() {
return {
newuser: {
firstName: '',
lastName: ''
}
};
});