$ scope。$ digest()不会填充select2下拉列表

时间:2015-05-23 14:09:39

标签: angularjs ui-select2 angular-digest

我使用ui-select2

有2个下拉列表
                        <label class="control-label" for="MakeSelect">Make </label>
                    <select class="form-control col-md-2" id="MakeSelect" name="make" ui-select2
                            ng-model="carDetails.make">
                        <option ng-if="!carDetails.make" value="">[SELECT]</option>
                        <option ng-repeat="make in makes" value="{{ make }}">{{ make}}</option>
                    </select>
                </div>
                <div class="col-md-5">
                <label class="control-label" for="ModelSelect">Model </label>
                <select class="form-control col-md-2" id="ModelSelect" name="make" ui-select2
                        ng-model="carDetails.model">
                    <option ng-repeat="model in models" value="{{ model }}">{{ make}}</option>
                </select>

在下拉列表中选择一个值&#34;制作&#34;我正在激活一个里面的手表,我加载了&#34;模型&#34;下拉列表。 然后,为了刷新GUI中的下拉列表内容,我调用$ scope。$ digest():

$scope.$watch('carDetails.make', function (make) {
    console.log('selected make is: ' + make);
    if (make == "") {
        return;
    }

    Parse.Cloud.run('getCarModels', {'Make': make}, {
        success: function (results) {
            $scope.parseModels = results.resultSet;
            $scope.models = results.distinctModels;
            $scope.$digest();
        },
        error: function () {
            console.log("Error: Failed to load models");
            console.log(Parse.Error);
        }
    });

问题是 $摘要第一个下拉列表的选定值变为空,没有它只是不刷新视图。< / p>

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

他们都指向相同的范围模型carDetails.make。所以,当然,第一个将变为null,因为第二个下拉列表将carDetails.make设置为null。此外,我不认为你需要使用摘要,但是,你应该使用$ scope。$ apply。但是,无论如何,angularjs应该运行摘要。

相关问题