Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将组合框元素默认设置为顶部角js_Javascript_Angularjs - Fatal编程技术网

Javascript 如何将组合框元素默认设置为顶部角js

Javascript 如何将组合框元素默认设置为顶部角js,javascript,angularjs,Javascript,Angularjs,每次选择框显示第一个元素为空时,我不会在选择框中得到值。 我不知道为什么有人能告诉我如何克服这个问题 我附加的问题,我所面临的具体问题,请在图片以及发送我的html看到 Html <div class="form-group"> <label class="col-lg-3 form-label">Brand:</label> <div class="c

每次选择框显示第一个元素为空时,我不会在选择框中得到值。 我不知道为什么有人能告诉我如何克服这个问题

我附加的问题,我所面临的具体问题,请在图片以及发送我的html看到

Html

<div class="form-group">
                        <label  class="col-lg-3 form-label">Brand:</label>
                        <div class="col-lg-5">

                            <select ng-show="categoryShow" class="form-control" ng-model="item.brand_id"  >
                                <option value="{{brand._id}}">{{brand.name}}</option>
                                <option ng-repeat="brand in brands" value="{{brand._id}}">{{brand.name}}</option>
                            </select>
                        </div>
                        <div class="col-lg-4">
                            <a ng-click='openBrandModel()'>
                                <i class="icon-plus-sign"></i>
                                Add Brand
                            </a>
                        </div>
                    </div>

品牌:
{{brand.name}
{{brand.name}
添加品牌
数据完美地绑定了一切,只是默认情况下没有显示我在ng repeat指令外使用的值

在图像中,你可以看到aslam的名称,所以我想取消它的显示,并重新制作为一个列表

Js用于设置品牌和品牌

itemService.getCategoryAndBrand.TypeGetCategoryAndBrand({}, $cookies.token, function(response){
    if(response.brands){

        var catchBrands = [];

        for(var i = 0; i < response.brands.length; i++){
            if(response.brands[i]._id == catchSelectedBrand){
                $scope.brand = response.brands[i];

            }else{
                catchBrands.push(response.brands[i]);
            }
        }

        $rootScope.brands = catchBrands;
    }
    if(response.categories){

        var catchCategories = [];

        for(var i = 0; i < response.categories.length; i++){
            if(response.categories[i]._id == catchSelectedCategory){
                $scope.category = response.categories[i];

            }else{
                catchCategories.push(response.categories[i]);
            }
        }

        $rootScope.categories = catchCategories;

    }

});
itemService.getCategoryAndBrand.TypeGetCategoryAndBrand({},$cookies.token,函数(响应){
如果(回应.品牌){
var=[];
对于(变量i=0;i
我认为您不需要HTML中的第一个选项

<option value="{{brand._id}}">{{brand.name}}</option>
{{brand.name}
您的所有选项看起来都来自下一行,带有
ng repeat
,此时似乎没有
brand
范围变量,因此我希望看到一个值和名称为空的选项

如果删除第一行,我希望看到空白选项消失,虽然我没有尝试过,不知道任何角度的逻辑,或者浏览器默认设置了一个空白选项…


编辑


其实看到了,,看起来很有可能,你只需要确保
项。brand_id
设置为现有选项的
\u id

好的,我写的第一个选项基本上就是我想在顶部显示的值,这就是为什么我写的是分开的,第二件事,当我看到html时,它默认情况下会显示这一行的来源我删除明确删除然后工作良好任何关于这个的想法thanxi也删除了第一行,正如你告诉我的,但我仍然不知道从哪里添加这一行,这不是空的sapce。你能在你设置
品牌
品牌
的地方发布JS吗?是
项目。品牌id
初始设置为
catchSelectedBrand
,以正确设置默认值?如果这样做了,我怀疑您可以删除我答案中的行(并将
If(response.brands)
block替换为
catchBrands=response.brands
,如果您愿意)。如果这不起作用,那么我不确定我还有其他想法。。。