ui-select禁用,如果为空

Ben*_*ers 7 angularjs ui-select

我是AngularJS的初学者.我有一个应用程序,它进行API调用,以获得汽车品牌,型号和年份的嵌套列表.我已经创建了三个ui-select元素来显示调用的结果,从汽车品牌列表开始,然后过滤到该品牌中的模型,最后是该模型的年份.我希望第二个和第三个选择在空时禁用,这样用户就无法尝试开始进入汽车模型.

<form class="form-horizontal" ng-controller="instant_quote" ng-submit="loadQuote()" name="quoteform">
    <div class="form-group" id="Make">
        <label for="Makes" class="col-md-3 control-label">Make</label>
        <div class="col-md-9">
            <ui-select
                    id="Makes"
                    ng-model="request.make">
                <ui-select-match placeholder="Enter a Make…">{{$select.selected.name}}</ui-select-match>
                <ui-select-choices repeat="choice in makes | filter: $select.search">
                    <div ng-bind-html="choice.name | highlight: $select.search"></div>
                </ui-select-choices>
            </ui-select>
        </div>
    </div>

    <div class="form-group" id="Model">
        <label class="col-md-3 control-label">Model</label>
        <div class="col-md-9">
            <ui-select
                    id="Models"
                    ng-model="request.model"
                    ng-disabled="request.make == 'false'">
                <ui-select-match placeholder="Enter a Model…">{{$select.selected.name}}</ui-select-match>
                <ui-select-choices repeat="choice in request.make.models | filter: $select.search">
                    <div ng-bind-html="choice.name | highlight: $select.search"></div>
                </ui-select-choices>
            </ui-select>
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

这是我试图确定每个选择是否为空的方法,基于当ng-model被初始化时Angular ui-select占位符不起作用

我的所有输入都没有被禁用.

seb*_*ier 9

我通常在myArray.length上使用ng-disable来获得0或!0并将其用作false和true.一直为我工作.

<select ng-model="model.a"
   ng-options="value for a in array"
   ng-disabled="!array.length">
</select>
Run Code Online (Sandbox Code Playgroud)

你的例子怎么样:

<ui-select
    id="Models"
    ng-model="request.model"
    ng-disabled="!request.make.length">
<ui-select-match placeholder="Enter a Model…">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="choice in request.make.models | filter: $select.search">
    <div ng-bind-html="choice.name | highlight: $select.search"></div>
</ui-select-choices>
Run Code Online (Sandbox Code Playgroud)

在你当前的代码request.make将返回[]而不是'false'...如果我理解得很好.