我是 Angular 的新手,我正在根据以下样板构建我的第一个实时页面:
https://github.com/jimakker/angular-express-bootstrap-seed
我无法让我的第一个表单提交。事实上,当我单击按钮时,什么也没有发生。下面给出了代码中的相关片段:
局部视图:
.row
form(ng-controller='RegisterCtrl')
#accordion.panel-group
//- Panel 1
.panel.panel-default
.panel-heading
h4(class='panel-title')
a(data-target='#collapse1', data-toggle="collapse", data-parent="#accordion", class="left-m-1em cursor-pointer") Basic Information
#collapse1.panel-collapse.collapse
.panel-body
.row
.col-lg-2(ng-controller='DropdownCtrl')
select(id="gender", ng-model='register.gender', ng-init="getValues('gender')", ng-options='r.value for r in results track by r.key', chosen, class="form-control", data-placeholder="Gender", data-toggle="tooltip", data-trigger="hover", data-placement="top", title="Gender")
option(value="")
//- More panels in between and finally, Panel 6
.panel.panel-default
.panel-heading
h4(class='panel-title')
a(data-target='#collapse6', data-toggle="collapse", data-parent="#accordion", class="left-m-1em cursor-pointer") Family
#collapse6.panel-collapse.collapse
.panel-body
.row
.col-lg-3.col-lg-offset-5
button(type="button", class="btn btn-success btn-lg", ng-click="saveProfile")
span(class="glyphicon glyphicon-ok-circle")
| Submit
我查看了呈现的输出并确认提交按钮确实在表单标记内。
控制器:
function RegisterCtrl($scope, $http) {
$scope.register = {};
$scope.saveProfile = function(item, event) {
alert("called this!");
var json = {
gender: $scope.register.gender,
marital_status: $scope.register.marital_status,
dob: $scope.register.dob,
height: $scope.register.height,
weight: $scope.register.weight,
complexion: $scope.register.complexion,
health: $scope.register.health
};
var responsePromise = $http.post("/api/register", json, {});
responsePromise.success(function(dataFromServer, status, headers, config) {
console.log(dataFromServer.title);
});
responsePromise.error(function(data, status, headers, config) {
alert("Submitting form failed!");
});
};
}
RegisterCtrl.$inject = ['$scope', '$http'];
我什至没有打第一个警报声明,我完全不确定为什么。另一个控制器 DropdownCtrl(用于单个表单元素)工作得很好,我可以使用控制器动态填充值。请帮我找到丢失的部分。