当我练习angularJS时,我是angularJS的初学者我遇到了问题。
问题是当我尝试使用ng-options
时,我在浏览器中看不到任何选定内容。
这是我的代码:
<div ng-controller="ShopController as shopCtrl">
<div ng-repeat="products in shopCtrl.product"
ng-hide="shopCtrl.isStartSell(products)">
<h1>{{ products.name}}</h1>
<span>{{products.p}}</span>
</div>
<select ng-model="shopCtrl.selectedProduct"
ng-options="product.name for product in shopCtrl.products"></select>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.1/angular.min.js"></script>
<script type="text/javascript">
(function(){
angular.module('ShoppingMall', []);
angular.module('ShoppingMall')
.controller('ShopController',function(){
var self = this;
this.product =[{
name: 'test01',
p: 1795,
description:'xxxxfff',
startSellTime:'2015-08-31 23:15:00'
},{
name: 'test02',
p: 1790,
description:'xxxxfff2',
startSellTime:'2014-09-20 23:15:00'
},{
name: 'test03',
p: 1793,
description:'xxxxfff2',
startSellTime:'2004-07-31 23:15:00'
}]
self.selectedProduct;
self.isStartSell = function(product){
var startSell = new Date(product.startSellTime);
var currentSellTime = new Date();
return startSell > currentSellTime;
}
});
})();
</script>
答案 0 :(得分:4)
更改
ng-options="product.name for product in shopCtrl.products"
到
ng-options="product.name for product in shopCtrl.product"
(删除最后的's'。