如何在 UI-select 中设置默认值



我尝试设置 ng-init 并给出 ng-model 的初始值,都失败了

$scope.newSubItem = function (scope) {
    var modal = $uibModal.open({
        backdrop: 'static',
        templateUrl: 'catalog/inputForm/partial/add_new_softwareOnTree.html',
        scope: newScope,
        controller: ['$scope', '$uibModalInstance','_', function ($scope, 
                    $uibModalInstance,_) {
        $scope.nodeRelationships4CatalogAddingSoftware = 
                codeTableService.nodeRelationships4CatalogAddingSoftware;
        $scope.targetNodes4ContainedInOrDependsOn = 
                  targetNodes4ContainedInOrDependsOn;
        $scope.nodes = nodes;
        $scope.newSoftware = {};
        var targetNodeId = nodeData && nodeData.id;
        $scope.newSoftware.target = 
              _.find(targetNodes4ContainedInOrDependsOn,function (o) {
                   return o.name ===  targetNodeId;
              });
        $scope.componentsQueryUrl = 
                  CONSTANTS.SERVICE_BLUEPRINT_COMPONENTS.PATH + "?query";
        $scope.submit = function () {           
         catalogCustomizedSoftwareComponentConfigService.onAddSoftwareSubmit(
              $scope,
              $scope.newSoftware,
              $scope.targetNodes4ContainedInOrDependsOn);
        $uibModalInstance.close($scope.targetNodes4ContainedInOrDependsOn);
           };
     }]
});
<div class="form-group row">
    <label class="col-lg-2 col-md-2 col-sm-2 control-label required">{{'Relationships' | translate}}</label>
    <div class="col-lg-9 col-md-9 col-sm-9">
        <div class="input-group">
        <ui-select ng-model="newSoftware.relationship"name="nodeRelationships" 
             required>
        <ui-select-match placeholder="{{'Please select a 
          relationship'|translate}}">{{$select.selected.name|translate}}
        </ui-select-match>
        <ui-select-choices repeat="item.id as item in 
          nodeRelationships4CatalogAddingSoftware | translateItemFilter: { 
         name:$select.search}">
        <div ng-bind-html="item.name | translate | highlight: $select.search"> 
        </div>
        </ui-select-choices>
        </ui-select>
     </div>
<span class="error" ng-show="addSoftWareForm.nodeRelationships.$touched && addSoftWareForm.nodeRelationships.$error.required">
{{'Please select a relationship'|translate}}
</span>
</div>
codeTableService.nodeRelationships4CatalogAddingSoftware = 
[
{id: "cloudify.relationships.contained_in", name: "contained_in"},
{id: "cloudify.relationships.depends_on", name: "depends_on"}
]

我想设置 ui-select 的初始值,而该值不显示。我希望将ui-select的初始值设置为"contained_in">

$scope.newSoftware.relationship = codeTableService.nodeRelationships4CatalogAddingSoftware[0].name

下拉列表包含两个值:

["contained_in", "installed_to"]

也许您所需要的只是将初始值分配给模型。我认为它不会显示在前端。

相关内容

  • 没有找到相关文章

最新更新