【问题标题】:select showing undefined but console log shows value angularjs选择显示未定义但控制台日志显示值 angularjs
【发布时间】:2018-10-23 11:31:20
【问题描述】:

我的选择如下

                <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

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

【问题讨论】:

  • 我希望您的选项包含您设置为模型的受益人价值。
  • Diljohn5741 我用 $scope.params.beneficiary = $scope.beneficiariesData[0].Name; 给出值;

标签: javascript html angularjs


【解决方案1】:

在服务功能块之外调用服务手段之前定义 $scope.params.beneficiary=null 然后再次测试

【讨论】:

    猜你喜欢
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 2019-09-14
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多