【问题标题】:angularjs select the first value in select boxangularjs在选择框中选择第一个值
【发布时间】:2015-06-19 08:48:09
【问题描述】:

我需要使用 angularjs 在选择框中突出显示第一个值“fullName”。 我正在使用 angularstrap 选择框。

控制器,

  $scope.accountInfo.owners = [  
   {  
      "accounts":null,
      "phoneumber":null,
      "email":null,
      "fullName":"MITA DASGUPTA",
      "mobilePhoneNumber":null,
      "noteFlag":false,
      "number":130000000484
   }
]

模板,

<button type="button" class="btn btn-default" placeholder="Pleasae select" 
  data-ng-model="owner.fullName" 
  data-html="1" 
  bs-options="owner as owner.fullName for owner in accountInfo.owners"  
  bs-select>
    Action <span class="caret"></span>
</button>

我尝试过这种方式,但默认情况下没有选择值。

【问题讨论】:

  • 我被夹在中间,任何人都可以尽快提供帮助。

标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap angularjs-ng-options


【解决方案1】:

您应该有一些不同的 ng-model 名称,您已经在 ng-options 中使用过 owner,例如 selectedOwner

<button type="button" class="btn btn-default" placeholder="Pleasae select" 
  data-ng-model="selectedOwner" 
  data-html="1" 
  bs-options="owner as owner.fullName for owner in accountInfo.owners"  
  bs-select>
    Action <span class="caret"></span>
</button>

然后你需要从控制器设置ng-model的值。

$scope.selectedOwner = $scope.accountInfo.owners[0];

【讨论】:

  • 非常感谢..它工作正常。从早上开始我一直在挣扎
  • @vishnu 很高兴为您提供帮助..谢谢 :)
【解决方案2】:

您忘记初始化捕获所选值的模型。您通常使用ng-init 来实现此目的,但也可以使用数组的第一个元素在控制器中初始化模型。 (以及相应的字段)。

【讨论】:

  • 我正在使用角带选择框
  • 我看到了。在文档中,他们在控制器中初始化了一个开始值。 IE。 $scope.selectedIcons = "["Globe","Heart"]";
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
  • 1970-01-01
  • 2020-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多