如何使用ng-options创建下拉列表

时间:2015-04-09 09:18:13

标签: angularjs ng-options

来自REST的JSON

http://localhost:8080/TestServer/webresources/com.rako.rma.product
{
brandBrandId: {
brandId: 2,
brandName: "Ticca",
isGun: true
},
created: "2015-04-09T12:06:37",
lotn: "1111",
productId: 1
}

HTML

<select data-ng-model="products.brandBrandId"
    data-ng-options="brand.brandName for brand in brandBrandId">                

控制器

$scope.productService = productService;
                $scope.products = productService.query();
                console.log('$scope.products---->' + $scope.products.length)//Always 0!!!!

                $scope.$watch('products.length', function (length) {
                    if (length) { // <= first time length is changed from undefined to 0
                        console.log('(watch) ' + $scope.products.length); // <= will log correct length aka 1
                    }
                });

问题

1)我应该如何在html中使用它? 2)如果我想同时显示id和名字,怎么样?

0 个答案:

没有答案