我创建了一个 rootScope 变量,例如
$rootScope.globalData = data;
$rootScope.globalData.chillerConditions.HeatSource.Value = "ST"; //Default Value
$scope.chillerConditions.HeatSource.Value = 1; //Default Value
data
我从 api 的返回值在哪里。还要创建一个范围变量,它是一个包含项目列表的对象。
$scope.chillerAttributes = data.ObjCandidateListChillerAttributes;
$scope.chillerConditions = data.ObjCandidateListConditions;
在 HTML 上,我有:
<select ng-model="chillerConditions.HeatSource.Value" style="width:53%;" ng-options="item.Id as item.Description for item in ValidRatingHeatSource" ng-change="heatSourceChanged()" id="ddRatingHeatSource" class="form-control search-select designComboboxHeight" data-container="body"></select>
这里ValidRatingHeatSource
是
$scope.ValidRatingHeatSource = \*list of items*\
在更改下拉菜单时,我编写了一个函数。在那里面
if($scope.chillerConditions.HeatSource.Value == 2)
{
$rootScope.globalData.chillerConditions.HeatSource.Value = "HW";
}
else
{
$rootScope.globalData.chillerConditions.HeatSource.Value = "ST";
}
到现在为止是我当前的代码。问题是:
当调用上述函数时,只要当前$rootScope
变量 ie$rootScope.globalData.chillerConditions.HeatSource.Value
更改为"HW"
or"ST"
它也更改$scope.chillerConditions.HeatSource.Value
为"HW"
or "ST"
。
为什么这样?
angularjs中是否有任何内置功能?请建议我是否犯了任何错误?也欢迎新的建议。