年份值未显示在angularjs中
我试图在HTML视图中显示年份值,但年份值根本不显示。虽然,我的其他值在条件未激活时显示(如信用卡),但当我激活它时,年份值不显示,而值来自控制器并显示在控制台中 以下是查看代码:-年份值未显示在angularjs中,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我试图在HTML视图中显示年份值,但年份值根本不显示。虽然,我的其他值在条件未激活时显示(如信用卡),但当我激活它时,年份值不显示,而值来自控制器并显示在控制台中 以下是查看代码:- <div class="col-xs-2 innerN" style="width: 14%;"> <select ng-disabled="page.creditcard.isDisabled" class="form-control innerN" pla
<div class="col-xs-2 innerN" style="width: 14%;">
<select ng-disabled="page.creditcard.isDisabled" class="form-control innerN" placeholder="YYYY" name="ccExpYear" ng-model="page.expyear" required style="border-left:none">
<option value="XX" selected ng-if="page.creditcard.isDisabled">XX</option>
<option ng-repeat="year in page.yearList" value="{{year}}" ng-if="!page.creditcard.isDisabled">{{year}}</option>
</select>
</div>
<!DOCTYPE html>
<html><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div class="col-xs-2 innerN" style="width: 14%;">
<select ng-disabled="page.creditcard.isDisabled" class="form-control innerN" placeholder="YYYY" name="ccExpYear" ng-model="page.expyear" required style="border-left:none">
<option value="XX" selected ng-if="page.creditcard.isDisabled">XX</option>
<option ng-repeat="year in page.yearList" value="{{year}}" ng-if="!page.creditcard.isDisabled">{{year}}</option>
</select>
</div>
XX
{{year}
以下是控制器代码:-
$scope.page.monthList = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", ];
$scope.page.yearList = [];
var d = new Date();
var year = d.getFullYear();
//$scope.page.yearList.push(year);
$scope.page.expyear = year;
console.log("Pawan2", $scope.page.expyear);
for (var i = 0; i < 21; i++) {
{
$scope.page.yearList.push(year + i);
};
}
$scope.years = $scope.page.yearList;
console.log("YearListPawan", $scope.page.yearList);
$scope.page.expmonth = "01";
$scope.monthList = "01";
// watcher
$scope.$watchGroup(['page.expmonth', 'page.expyear'], function(newValues, oldValues, scope) {
//MM-YYYY
if (typeof newValues[1] == "undefined" || typeof newValues[0] == "undefined") scope.authorize.creditCard
.expirationDate = null;
else $scope.authorize.creditCard.expirationDate = newValues[1] + "-" + newValues[0];
console.log("Pawan", $scope.authorize.creditCard.expirationDate)
}, true);
$scope.page.monthList=[“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”、“11”、“12”];
$scope.page.yearList=[];
var d=新日期();
var year=d.getFullYear();
//$scope.page.yearList.push(年);
$scope.page.expyear=年份;
log(“Pawan2”,$scope.page.expyear);
对于(变量i=0;i<21;i++){
{
$scope.page.yearList.push(年份+i);
};
}
$scope.years=$scope.page.yearList;
log(“YearListPawan”,$scope.page.yearList);
$scope.page.expmonth=“01”;
$scope.monthList=“01”;
//观察者
$scope.$watchGroup(['page.expmonth','page.expyear'],函数(newValues,oldValues,scope){
//年月日
如果(新值类型[1]=“未定义”| |新值类型[0]=“未定义”)scope.authorize.creditCard
.expirationDate=null;
else$scope.authorize.creditCard.expirationDate=newValues[1]+“-”+newValues[0];
console.log(“Pawan”,$scope.authorize.creditCard.expirationDate)
},对);
我希望,我很清楚能得到这个问题的答案。
PS:THnx提前获取帮助。您应该使用ng value而不是value:-
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.page={};
$scope.page.monthList=[“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”、“11”、“12”];
$scope.page.yearList=[];
var d=新日期();
var year=d.getFullYear();
//$scope.page.yearList.push(年);
$scope.page.expyear=年份;
log(“Pawan2”,$scope.page.expyear);
对于(变量i=0;i<21;i++){
{
$scope.page.yearList.push(年份+i);
};
}
$scope.years=$scope.page.yearList;
$scope.authorize={信用卡:{expirationDate:'date'};
log(“YearListPawan”,$scope.page.yearList);
$scope.page.expmonth=“01”;
$scope.monthList=“01”;
//观察者
$scope.$watchGroup(['page.expmonth','page.expyear'],函数(newValues,oldValues,scope){
//年月日
if(新值类型[1]=“未定义”| |新值类型[0]=“未定义”)
$scope.authorize.creditCard.expirationDate=null;
其他的
$scope.authorize.creditCard.expirationDate=newValues[1]+“-”+newValues[0];
console.log(“Pawan”,$scope.authorize.creditCard.expirationDate)
},对);
});代码>
XX
{{year}
您应该使用ng值而不是值:-
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.page={};
$scope.page.monthList=[“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”、“11”、“12”];
$scope.page.yearList=[];
var d=新日期();
var year=d.getFullYear();
//$scope.page.yearList.push(年);
$scope.page.expyear=年份;
log(“Pawan2”,$scope.page.expyear);
对于(变量i=0;i<21;i++){
{
$scope.page.yearList.push(年份+i);
};
}
$scope.years=$scope.page.yearList;
$scope.authorize={信用卡:{expirationDate:'date'};
log(“YearListPawan”,$scope.page.yearList);
$scope.page.expmonth=“01”;
$scope.monthList=“01”;
//观察者
$scope.$watchGroup(['page.expmonth','page.expyear'],函数(newValues,oldValues,scope){
//年月日
if(新值类型[1]=“未定义”| |新值类型[0]=“未定义”)
$scope.authorize.creditCard.expirationDate=null;
其他的
$scope.authorize.creditCard.expirationDate=newValues[1]+“-”+newValues[0];
console.log(“Pawan”,$scope.authorize.creditCard.expirationDate)
},对);
});代码>
XX
{{year}
以下是我应用于该场景的解决方案-
以下是控制器代码,变化不大:-
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.page = {};
$scope.page.monthList = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", ];
$scope.page.yearList = [];
var d = new Date();
var year = d.getFullYear();
var addYears = function () {
var d = new Date();
var year = d.getFullYear();
$scope.page.yearList = [];
var i = 0;
for (i = 0; i < 40; i++) {
$scope.page.yearList.push(year.toString());
year++;
}
}
addYears();
$scope.years = $scope.page.yearList;
$scope.page.expyear = d.getFullYear();
$scope.page.expmonth = "01";
$scope.monthList = "01";
// watcher
$scope.$watchGroup(['page.expmonth', 'page.expyear'], function(newValues, oldValues, scope) {
//MM-YYYY
if(typeof newValues[1] == "undefined" || typeof newValues[0] == "undefined")
scope.authorize.creditCard.expirationDate = null;
else
$scope.authorize.creditCard.expirationDate = newValues[1] + "-" + newValues[0];
console.log("Pawan", $scope.authorize.creditCard.expirationDate)
}, true);
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.page={};
$scope.page.monthList=[“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”、“11”、“12”];
$scope.page.yearList=[];
var d=新日期();
var year=d.getFullYear();
var addYears=函数(){
var d=新日期();
var year=d.getFullYear();
$scope.page.yearList=[];
var i=0;
对于(i=0;i<40;i++){
$scope.page.yearList.push(year.toString());
年份++;
}
}
addYears();
$scope.years=$scope.page.yearList;
$scope.page.expyear=d.getFullYear();
$scope.page.expmonth=“01”;
$scope.monthList=“01”;
//观察者
$scope.$watchGroup(['page.expmonth','page.expyear'],函数(newValues,oldValues,scope){
//年月日
if(新值类型[1]=“未定义”| |新值类型[0]=“未定义”)
scope.authorize.creditCard.expirationDate=null;
其他的
$scope.authorize.creditCard.expirationDate=newValues[1]+“-”+newValues[0];
console.log(“Pawan”,$scope.authorize.creditCard.expirationDate)
},对);
以下是查看代码:-
<div class="col-xs-2 innerN" style="width: 14%;">
<select ng-disabled="page.creditcard.isDisabled" class="form-control innerN" placeholder="YYYY" name="ccExpYear" ng-model="page.expyear" required style="border-left:none">
<option value="XX" selected ng-if="page.creditcard.isDisabled">XX</option>
<option ng-repeat="year in page.yearList" value="{{year}}" ng-if="!page.creditcard.isDisabled">{{year}}</option>
</select>
</div>
<!DOCTYPE html>
<html><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div class="col-xs-2 innerN" style="width: 14%;">
<select ng-disabled="page.creditcard.isDisabled" class="form-control innerN" placeholder="YYYY" name="ccExpYear" ng-model="page.expyear" required style="border-left:none">
<option value="XX" selected ng-if="page.creditcard.isDisabled">XX</option>
<option ng-repeat="year in page.yearList" value="{{year}}" ng-if="!page.creditcard.isDisabled">{{year}}</option>
</select>
</div>
XX
{{year}
希望,这将对其他人有所帮助。以下是我应用于该场景的解决方案-
以下是控制器代码,变化不大:-
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.page = {};
$scope.page.monthList = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", ];
$scope.page.yearList = [];
var d = new Date();
var year = d.getFullYear();
var addYears = function () {
var d = new Date();
var year = d.getFullYear();
$scope.page.yearList = [];
var i = 0;
for (i = 0; i < 40; i++) {
$scope.page.yearList.push(year.toString());
year++;
}
}
addYears();
$scope.years = $scope.page.yearList;
$scope.page.expyear = d.getFullYear();
$scope.page.expmonth = "01";
$scope.monthList = "01";
// watcher
$scope.$watchGroup(['page.expmonth', 'page.expyear'], function(newValues, oldValues, scope) {
//MM-YYYY
if(typeof newValues[1] == "undefined" || typeof newValues[0] == "undefined")
scope.authorize.creditCard.expirationDate = null;
else
$scope.authorize.creditCard.expirationDate = newValues[1] + "-" + newValues[0];
console.log("Pawan", $scope.authorize.creditCard.expirationDate)
}, true);
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.page={};
$scope.page.monthList=[“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”、“11”、“12”];
$scope.page.yearList=[];
var d=新日期();
风险年