Angular $scope 在表单提交时未定义
Angular $scope undefined on form submit
我不知道我做错了什么,谁能看出我做错了什么?我只想将我的表单输入(在本例中为日期选择器)传递给控制器函数,但我尝试访问的所有内容都显示为未定义!
这是我的表格
<form ng-submit="showRefinedGameMarkers(refinements)">
<div class="list">
<div class="datepickers">
From Date:
<label class="item item-input">
<input ng-controller="DatepickerCtrl"
type="text"
placeholder="Pick date"
ng-model="refinements.from_datepicker"
name="from_datepicker"
ng-click="opendateModal()"
readonly>
</label>
</div>
这是我的控制器class
.controller('MapController', function($scope, $ionicLoading, gameFactory, $compile) {
$scope.showRefinedGameMarkers = function(refinements) {
$scope.refinements = refinements;
console.log($scope.refinements);
...
}
})
我试过的所有方法都显示为未定义,真烦人!任何帮助将不胜感激谢谢
添加$scope.refinements = {};在控制器的顶部。
您不需要将 refinements
传递给您的提交函数,因为它使用 ng-model 和 angular 的绑定将为您更改 $scope.refinements
。
此外,您需要在控制器中初始化 refinements
变量。
$scope.refinements = {}
我不知道我做错了什么,谁能看出我做错了什么?我只想将我的表单输入(在本例中为日期选择器)传递给控制器函数,但我尝试访问的所有内容都显示为未定义!
这是我的表格
<form ng-submit="showRefinedGameMarkers(refinements)">
<div class="list">
<div class="datepickers">
From Date:
<label class="item item-input">
<input ng-controller="DatepickerCtrl"
type="text"
placeholder="Pick date"
ng-model="refinements.from_datepicker"
name="from_datepicker"
ng-click="opendateModal()"
readonly>
</label>
</div>
这是我的控制器class
.controller('MapController', function($scope, $ionicLoading, gameFactory, $compile) {
$scope.showRefinedGameMarkers = function(refinements) {
$scope.refinements = refinements;
console.log($scope.refinements);
...
}
})
我试过的所有方法都显示为未定义,真烦人!任何帮助将不胜感激谢谢
添加$scope.refinements = {};在控制器的顶部。
您不需要将 refinements
传递给您的提交函数,因为它使用 ng-model 和 angular 的绑定将为您更改 $scope.refinements
。
此外,您需要在控制器中初始化 refinements
变量。
$scope.refinements = {}