我有以下代码:
<div layout="row" class="row" layout-xs="column" ng-repeat="dataset in datasetsEnv">
<div class="large-12 columns end" flex>
<md-input-container layout="row" flex>
<label>Environment setting for dataset {{dataset.datasetName}}:</label>
<md-select ng-model="model.environments" style="min-width:410px;">
<md-option ng-repeat="environment in dataset.environments" value="{{environment.DbEnvironmentId}}" ng-selected="isUserEnvSelected(environment)">{{environment.DisplayName}}</md-option>
</md-select>
<div></div>
</md-input-container>
</div>
使用上面的代码我生成一个数字mdSelect指令但我的问题是它们都绑定到一个模型ng-model="model.environments"
。有没有办法将每个生成的mdSelect绑定到一个我可以在后面引用的唯一模型?
答案 0 :(得分:0)
你试过这样的事吗:
<div layout="row" class="row" layout-xs="column" ng-repeat="dataset in datasetsEnv">
<div class="large-12 columns end" flex>
<md-input-container layout="row" flex>
<label>Environment setting for dataset {{dataset.datasetName}}:</label>
<md-select ng-model="model.environments.dataset[datasetName]" style="min-width:410px;">
<md-option ng-repeat="environment in dataset.environments" value="{{environment.DbEnvironmentId}}" ng-selected="isUserEnvSelected(environment)">{{environment.DisplayName}}</md-option>
</md-select>
<div></div>
</md-input-container>
这会向dataset
添加一个属性model.environments
,其中dataset
为array
且datasetname
等于模型值。
答案 1 :(得分:0)
这应该没问题。
<div layout="row" class="row" layout-xs="column" ng-repeat="dataset in datasetsEnv">
<div class="large-12 columns end" flex>
<md-input-container layout="row" flex>
<label>Environment setting for dataset {{dataset.datasetName}}:</label>
<md-select ng-model="dataset.selectedEnvironment" style="min-width:410px;">
<md-option ng-repeat="environment in dataset.environments" value="{{environment.DbEnvironmentId}}" ng-selected="isUserEnvSelected(environment)">{{environment.DisplayName}}</md-option>
</md-select>
<div></div>
</md-input-container>