AngularJS:某些表单字段未与viewmodel绑定
我正在编写一个表单,将输入与angularJS模型绑定。由于某些原因,只有某些字段绑定到模型(AngularJS:某些表单字段未与viewmodel绑定,angularjs,data-binding,controller,Angularjs,Data Binding,Controller,我正在编写一个表单,将输入与angularJS模型绑定。由于某些原因,只有某些字段绑定到模型(vm.customer)。例如,vm.last_name和vm.email是绑定的。但是vm.first_name和vm.gender并没有从输入绑定到模型 /* AddCustomer.js */ (function (angular) { 'use strict'; angular.module('app', []); function controller($scope) {
vm.customer
)。例如,vm.last_name和vm.email是绑定的。但是vm.first_name和vm.gender并没有从输入绑定到模型
/* AddCustomer.js */
(function (angular) {
'use strict';
angular.module('app', []);
function controller($scope) {
var vm = this;
vm.genders = ["Male", "Female", "Other"];
vm.customer = {
first_name: 'Susan',
last_name: 'BOyle',
email: 's.boyle@singwell.com',
ip_address: '192.168.1.120',
gender: vm.genders[1]
}
vm.addCustomer = function($scope) {
console.log("bout to add a user");
};
vm.$onInit = function() {
};
}
// dep. injecion
controller.$inject = ['$scope'];
angular
.module('app')
.controller('AddCustomer', controller);
})(window.angular);
这是html文件
/* add-customer-view.html */
<form ng-app="app" ng-controller="AddCustomer as vm">
<pre>
customer = {{ vm.customer | json }}
</pre>
<div class="form-row">
<div class="form-group col-md-6">
<label>First</label>
<input class="form-control" type="text" ng-model"vm.customer.first_name" ng-model-options="{ updateOn: 'blur' }">
</div>
<div class="form-group col-md-6">
<label>Last</label>
<input class="form-control" type="text" ng-model="vm.customer.last_name">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label class="col-form-label">Email</label>
<input class="form-control" type="email" ng-model="vm.customer.email">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<div class="form-check form-check-inline" ng-repeat="gender in vm.genders">
<input type="radio" name="gender" ng-model"vm.customer.gender" value="vm.genders[{{$index}}]">
<label class="form-check-label">{{ gender }}</label>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label class="col-form-label">IP Address</label>
<input class="form-control" type="text" ng-model="vm.customer.ip_address">
</div>
</div>
<div class="form-row">
<button type="submit" class="btn btn-primary" ng-click="vm.addCustomer()">Add Customer</button>
</div>
/*add-customer-view.html*/
客户={vm.customer | json}
第一
最后的
电子邮件
{{性别}
IP地址
添加客户
指向代码段的链接:。任何见解都会非常有用 1)在这两种情况下(名字、性别)都缺少=
操作符
2) 您需要按如下方式替换输入值:
谢谢。我昨天就知道了。但这花了我足够长的时间。从现在起,我需要使用过梁。
<input type="radio" name="gender" ng-model="vm.customer.gender" value="{{gender}}">