从 $http 服务返回选项列表时,ng-option 不工作
ng-option is not working when option list is returned from $http service
我有以下代码,returns 我在我的控制器中提供服务列表
mosServiceFactory.allOffers().then(function (response) {
$scope.Offers = response.data.offers;
console.log(JSON.stringify($scope.Offers));
});
我在 HTML 中使用以下代码显示 select 标签
中的选项列表
<select ng-model="offerList" ng-option="offer.campaignName for offer in Offers"></select>
我在服务中得到的 Json 响应是(存储在 $scope.Offers 中):
[{
"offerId": "8a1b0cb44e76781e014e767e7b120001",
"campaignName": "Instant July Offer",
"campaignDescription": "30% discount on Apple",
"campaignStartDate": "2015-07-12",
"campaignEndDate": "2015-07-22",
"status": "ACTIVE",
"enrollmentId": "8a1b0cb44e66dba9014e670a0f8c0001",
"discount": "30",
"discountUnit": "Discount %",
"dateCreated": "2015-07-10",
"dateModified": null,
"instantOffId": 1,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}, {
"offerId": "8a6804c24e53e4ab014e53fe72770000",
"campaignName": "July2",
"campaignDescription": "Weekend Offer from first 100 customers.",
"campaignStartDate": "2015-07-08",
"campaignEndDate": "2015-07-11",
"status": "EXPIRED",
"enrollmentId": "8a1b0cb44e4e8e2b014e53333d5d0001",
"discount": "20",
"discountUnit": "Discount $",
"dateCreated": "2015-07-03",
"dateModified": null,
"instantOffId": 0,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}, {
"offerId": "8a1b0cb44e61e491014e622088460003",
"campaignName": "Weekend discount",
"campaignDescription": "50% discount",
"campaignStartDate": "2015-07-06",
"campaignEndDate": "2015-07-07",
"status": "INACTIVE",
"enrollmentId": "8a1b0cb44e61e491014e6207fbaa0001",
"discount": "50",
"discountUnit": "Discount %",
"dateCreated": "2015-07-06",
"dateModified": "2015-07-06",
"instantOffId": 0,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}, {
"offerId": "8a1b0cb44e766cd5014e766ed37b0000",
"campaignName": "abc offer",
"campaignDescription": "50% discount on Apple",
"campaignStartDate": "2015-07-12",
"campaignEndDate": "2015-07-17",
"status": "ACTIVE",
"enrollmentId": "8a1b0cb44e61e491014e6207fbaa0001",
"discount": "50",
"discountUnit": "Discount %",
"dateCreated": "2015-07-10",
"dateModified": null,
"instantOffId": 1,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}]
它与这个 plunker 非常相似 http://plnkr.co/edit/fMAGnonoM9JvuIKvnOYU?p=preview
唯一不同的是我得到的是响应列表。
但不知何故,我在 HTML 文件中看不到选项!
应该是ng-options
而不是ng-option
我有以下代码,returns 我在我的控制器中提供服务列表
mosServiceFactory.allOffers().then(function (response) {
$scope.Offers = response.data.offers;
console.log(JSON.stringify($scope.Offers));
});
我在 HTML 中使用以下代码显示 select 标签
中的选项列表<select ng-model="offerList" ng-option="offer.campaignName for offer in Offers"></select>
我在服务中得到的 Json 响应是(存储在 $scope.Offers 中):
[{
"offerId": "8a1b0cb44e76781e014e767e7b120001",
"campaignName": "Instant July Offer",
"campaignDescription": "30% discount on Apple",
"campaignStartDate": "2015-07-12",
"campaignEndDate": "2015-07-22",
"status": "ACTIVE",
"enrollmentId": "8a1b0cb44e66dba9014e670a0f8c0001",
"discount": "30",
"discountUnit": "Discount %",
"dateCreated": "2015-07-10",
"dateModified": null,
"instantOffId": 1,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}, {
"offerId": "8a6804c24e53e4ab014e53fe72770000",
"campaignName": "July2",
"campaignDescription": "Weekend Offer from first 100 customers.",
"campaignStartDate": "2015-07-08",
"campaignEndDate": "2015-07-11",
"status": "EXPIRED",
"enrollmentId": "8a1b0cb44e4e8e2b014e53333d5d0001",
"discount": "20",
"discountUnit": "Discount $",
"dateCreated": "2015-07-03",
"dateModified": null,
"instantOffId": 0,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}, {
"offerId": "8a1b0cb44e61e491014e622088460003",
"campaignName": "Weekend discount",
"campaignDescription": "50% discount",
"campaignStartDate": "2015-07-06",
"campaignEndDate": "2015-07-07",
"status": "INACTIVE",
"enrollmentId": "8a1b0cb44e61e491014e6207fbaa0001",
"discount": "50",
"discountUnit": "Discount %",
"dateCreated": "2015-07-06",
"dateModified": "2015-07-06",
"instantOffId": 0,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}, {
"offerId": "8a1b0cb44e766cd5014e766ed37b0000",
"campaignName": "abc offer",
"campaignDescription": "50% discount on Apple",
"campaignStartDate": "2015-07-12",
"campaignEndDate": "2015-07-17",
"status": "ACTIVE",
"enrollmentId": "8a1b0cb44e61e491014e6207fbaa0001",
"discount": "50",
"discountUnit": "Discount %",
"dateCreated": "2015-07-10",
"dateModified": null,
"instantOffId": 1,
"basketOfferItemId": null,
"basketOfferQuantity": 0,
"basketQuantity": 0
}]
它与这个 plunker 非常相似 http://plnkr.co/edit/fMAGnonoM9JvuIKvnOYU?p=preview
唯一不同的是我得到的是响应列表。
但不知何故,我在 HTML 文件中看不到选项!
应该是ng-options
而不是ng-option