Я попытался установить ng-init и дать начальное значение ng-модели, все не удалось
$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, равное «contains_in»
$scope.newSoftware.relationship = codeTableService.nodeRelationships4CatalogAddingSoftware[0].name
И выпадающий список содержит два значения:
["contained_in", "installed_to"]