angularjs JavaScript 继承,无法将数据从视图绑定到控制器
angularjs JavaScript inheritance, fail to bind data from view to a controller
我想做的是从表单中获取数据 在我的控制器中使用它在 HTTP
post 调用中,但它不起作用
我知道我可能有范围继承方面的问题,但我无法解决它。
这是我的控制器代码:
.controller('SignUpCtrl', function($scope, $http, $state) {
$scope.submit = function() {
var url = 'http://localhost:3000/register';
var user = {
email: $scope.email,
password: $scope.password,
};
console.log($scope.user);
$http.post(url, user)
.success(function(res){
console.log('You are now Registered');
//$state.go('app.items');
})
.error(function(err){
console.log('Could not register');
// $state.go('error');
});
};
})
这是我的模板代码:
<form name="register">
<div class="list">
<label class="item item-input no-border">
<input name="fullname" type="text" ng-model="fullname" placeholder="Full Name" required="">
</label>
<label class="item item-input">
<input name="email" type="email" ng-model="user.email" placeholder="Email" required="">
</label>
<p class="blue-font" ng-show="register.email.$dirty && register.email.$invalid">Please Write valid Email.</p>
<label class="item item-input">
<input name="password" type="password" ng-model="user.password" placeholder="Password" required="">
</label>
<button ng-click="submit();" ng-disabled="register.$invalid" type="submit" class="button signup-btn sharb-border white-font blue-bg-alt border-blue-alt ">
Sign Up
</button>
</div>
</form>
注意:我尝试了 ng-submit 它并不是真正的问题
控制器内部。
.controller('SignUpCtrl', function($scope, $http, $state) {
$scope.user = {
email: '',
password: ''
};
$scope.submit = function() {
还有这个
var user = {
email: $scope.user.email,
password: $scope.user.password
};
同时在 ng-click
中删除 ;
<button ng-click="submit()" ...>
尝试使用 rootScope (docs.angularjs.org/$rootScope")。
我想做的是从表单中获取数据 在我的控制器中使用它在 HTTP
post 调用中,但它不起作用
我知道我可能有范围继承方面的问题,但我无法解决它。 这是我的控制器代码:
.controller('SignUpCtrl', function($scope, $http, $state) {
$scope.submit = function() {
var url = 'http://localhost:3000/register';
var user = {
email: $scope.email,
password: $scope.password,
};
console.log($scope.user);
$http.post(url, user)
.success(function(res){
console.log('You are now Registered');
//$state.go('app.items');
})
.error(function(err){
console.log('Could not register');
// $state.go('error');
});
};
})
这是我的模板代码:
<form name="register">
<div class="list">
<label class="item item-input no-border">
<input name="fullname" type="text" ng-model="fullname" placeholder="Full Name" required="">
</label>
<label class="item item-input">
<input name="email" type="email" ng-model="user.email" placeholder="Email" required="">
</label>
<p class="blue-font" ng-show="register.email.$dirty && register.email.$invalid">Please Write valid Email.</p>
<label class="item item-input">
<input name="password" type="password" ng-model="user.password" placeholder="Password" required="">
</label>
<button ng-click="submit();" ng-disabled="register.$invalid" type="submit" class="button signup-btn sharb-border white-font blue-bg-alt border-blue-alt ">
Sign Up
</button>
</div>
</form>
注意:我尝试了 ng-submit 它并不是真正的问题
控制器内部。
.controller('SignUpCtrl', function($scope, $http, $state) {
$scope.user = {
email: '',
password: ''
};
$scope.submit = function() {
还有这个
var user = {
email: $scope.user.email,
password: $scope.user.password
};
同时在 ng-click
;
<button ng-click="submit()" ...>
尝试使用 rootScope (docs.angularjs.org/$rootScope")。