我正在使用UI-Bootstrap,所以我可以使用它们Angular和Bootstrap。我想访问“controllerCountries”控制器所具有的选择标签的值,并将该值用作参数来填充选择“selectedServices”。我想这样做是因为程序的逻辑是,当我在选择标记中选择一个国家列表的国家时,使用该值填充另一个选择标记。填写第二个使用AngularJS选择标签的第一个选择标签?
我的HTML是在这里:
<div style="margin-top: 15px" class="col-md-6">
<div id="form-pais"class="form-group">
<label class=" control-label">Country:</label>
<div class="selectContainer">
<select ng-controller="controllerCountries" class="form-control" id="abvCountry" name="abvCountry" ng-model="countrySelected">
<option value="gt">Guatemala</option>
<option value="sl">El Salvador</option>
<option value="hn">Honduras</option>
</select>
</div>
</div>
</div>
<div style="margin-top: 15px" class="col-md-6">
<div class="form-group">
<label class=" control-label">Services:</label>
<div ng-controller="controllerServices" class="selectContainer">
<select class="form-control" id="selectServices"ng-model="servicios" ng-options="y for (x, y) in serviciosgt" text="">
</select>
</div>
我的JS文件看起来像这样:
//Heres the list of services in the objects. I use this to fill the second select.
app.controller('controllerServices', function($scope)
{
$scope.serviciosgt =
{
consMiami : "Consolidación Miami",
contCompletosGT: "Contenedores Completos",
cargMartConsolidadGT : "Carga Maritima Consolidada",
cargAereaRegularGT: "Carga Áerea Regular"
};
$scope.serviciosSL =
{
contCompletosSl : "Contenedores Completos",
cargMartConsolidadSl: "Carga Marítima Consolidada",
cargAereaRegularSl: "Carga Áerea Regular"
};
$scope.serviciosHN =
{
contCompletosHN : "Contenedores Completos",
cargMartConsolidadHN: "Carga Marítima Consolidada",
cargAereaRegularHN: "Carga Áerea Regular"
};
});
//Heres the controller to fill.
app.controller('controllerCountries', function($scope)
{
$scope.countrySelected ='';
$scope.$watch('countrySelected', function() {
if($scope.countrySelected=="gt")
{
console.log("Select GT");
}
else if($scope.countrySelected=="sl")
{
console.log("Select SL");
}
else if($scope.countrySelected=="hn")
{
console.log("Select HN");
}
});
});
现在我可以访问的第一个 “controllerCountries” 的价值和日志在控制台上的价值,但多数民众赞成它。而且,正如你所看到的,我用第一个对象填充选区,但是我想让他们变成动态的。任何人都可以帮助我。如果你看我的代码是错误的,欢迎你解决它。
问候和感谢。所有的
[动态NG-选项(https://stackoverflow.com/que stions/26518220/angularjs动态-NG选项对链接两个下拉菜单) –