Kerouac Jack
Kerouac Jack

Reputation: 1

how can I set default value in ui-select

I have tried set ng-init and give the initial value of ng-model, all failed

$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"}
]

I want to set initial value of ui-select, while the value does not display. I expect to set the initial value of ui-select equals "contained_in"

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

And dropdown list contains two value:

["contained_in", "installed_to"]

Upvotes: 0

Views: 450

Answers (1)

Gustavo Cirilo
Gustavo Cirilo

Reputation: 21

Maybe all you need is to assign the initial value to the model. I don't think it will display in the frontend.

Upvotes: 1

Related Questions