[英]ng-model undefined in controller
the ng-model I have in html has a dot in it. 我在html中的ng-model中有一个点。 let's take a look 让我们来看看
step1.html file step1.html文件
<div class="col-xs-12 col-sm-9">
<select id="plateId" ng-model="selectedPlate.plate" ng-options="plate.id as (plate.wafer_id + ' - ' + plate.serial_number) for plate in plates" />
<option value="">Select</option>
</select>
</div>
It's simply a form-wizard using ui-router. 这只是使用ui-router的表单向导。
This is my other html file. 这是我的另一个html文件。 In step 3 the user pushes the button. 在步骤3中,用户按下按钮。
<button class="btn btn-success btn-next" ng-click="storePlatesInspection()">
Submit
<i class="ace-icon fa icon-on-right"></i>
</button>
And my controller look like this. 我的控制器看起来像这样。
angular.module('sxroApp')
.controller('plateInspectionCtrl', function ($scope, PlatesInspectionFactory, PlatesFactory, PlateQualityFactory, EquipmentStatusCodesFactory, PlateContainersFactory, $location) {
// object to hold all the data for plate inspection
$scope.data = [];
$scope.selectedPlate = {};
$scope.inspectionData = {
equipment_status_codes_id: 1,
plate_container_id: 1,
plate_container_slot: 34,
plate_quality_id: 1
}
PlatesFactory.query(function (plates) {
$scope.plates = plates;
});
/* $scope.getSelectedPlate = function(plate)
{
$scope.data.push({
plate_id : plate.id
});*/
// console.log($scope.selectedPlate.id)
//alert(item.wafer_id)
//PlatesInspectionFactory.update( {id : $scope.plateid[0].plate_id}, $scope.inspectionData)
PlateQualityFactory.query(function (platequality) {
$scope.platequality = platequality;
})
PlateContainersFactory.query(function (plateContainers) {
$scope.plateContainers = plateContainers;
});
EquipmentStatusCodesFactory.query(function (statuscodes) {
$scope.statuscodes = statuscodes;
});
$scope.storePlatesInspection = function () {
alert($scope.selectedPlate.plate.id); // not working
alert($scope.selectedPlate.plate.$id); // not working
}
});
I also tried 我也试过
alert($scope.selectedPlate.plate); // undefined is the result.
I basically followed what this gentleman was saying 我基本上听了这位先生说的话
Ng-model does not update controller value NG模型不会更新控制器值
Would someone show me what I am doing wrong? 有人会告诉我我做错了吗?
here is an image of the form form 这是表格形式的图像
I am trying to use the model to get the selection the user does during the wizard process. 我正在尝试使用该模型来获取用户在向导过程中所做的选择。
update #1 : I have updated the code above. 更新#1 :我已经更新了上面的代码。
Change your html to 将您的html更改为
<select id="plateId"
ng-model="selectedPlate.plate"
ng-options="plate for plate in plates"/>
<option value="">Select</option>
</select>
See different way of ddl bindings 查看DDL绑定的不同方式
I'm not sure why alert($scope.selectedPlate.plate);
我不确定为什么alert($scope.selectedPlate.plate);
is not working, but you are passing the value of your ID property to $scope.selectedPlate.plate
, so it won't hold a "plate object" with an ID property in it, it's just a number (or whatever ID is). 不起作用,但是您将ID属性的值传递给$scope.selectedPlate.plate
,因此它不会保存带有ID属性的“板对象”,它只是一个数字(或任何ID) 。
I haven't used ui-router before but it may be that you have specified a directive or a routing path along with the controllerAs property. 我以前没有使用过ui-router,但可能是您指定了指令或路由路径以及controllerAs属性。 If controllerAs is specified then the variables stored on $scope in the controller would be accessed via the controllerAs value in the view html. 如果指定了controllerAs,则将通过html视图中的controllerAs值访问存储在$ scope中的变量。
For example, if the directive was declared as such: 例如,如果指令是这样声明的:
angular.module('sxroApp')
.directive('plateInspectionDirective', function () {
return {
restrict: 'A',
templateUrl: 'plateInspection.html',
controller: plateInspectionCtrl,
controllerAs: 'plateInspection',
scope: {
}
};
});
Then the view would require the controller name plateInspection to access the variables on it's scope. 然后,该视图将需要控制器名称plateInspection来访问其作用域上的变量。
<div class="col-xs-12 col-sm-9">
<select id="plateId" ng-model="plateInspection.selectedPlate.plate" ng-options="plate.id as (plate.wafer_id + ' - ' + plate.serial_number) for plate in plateInspection.plates" />
<option value="">Select</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.