选择显示未定义,但控制台日志显示值angularjs

时间:2018-10-23 11:31:21

标签: javascript html angularjs

我的选择如下

                <div class="inputCol">
                    <label>{{'FrequentBeneficiary'  | translate}}</label>
                    <select ng-model="params.beneficiary" ng-options="option.Name as option.Name for option in beneficiaryData"></select>
                </div>
            </div>

我的服务呼叫代码:

  bcsSQLiteStorage.getDataDB(BeneficiariesKey).then(function (data) {
                if (data.rows.length > 0) {

                    console.log("entrou no data.rows.length");
                    $scope.beneficiariesData = angular.fromJson(data.rows.item(0).value);
                    $scope.AccountLoaded = true;
                    MobileLoading.Ionic.hide();
                    console.log("Beneficiaries Data " + JSON.stringify($scope.beneficiariesData));
                    $scope.params.beneficiary = $scope.beneficiariesData[0].Name;
                    console.log($scope.params.beneficiary);
                }

然后我的console.log会很好地打印出名称

 console.log($scope.params.beneficiary);

prints the name correctly, does not print undefined

但是我的选择在测试时显示未定义 为什么?我的选择有问题吗?

1 个答案:

答案 0 :(得分:0)

在调用service表示超出服务功能块之前,先定义$ scope.params.beneficiary = null,然后再次测试