Angularjs rootScope正在更新作用域变量

Angularjs rootScope正在更新作用域变量,angularjs,scope,rootscope,Angularjs,Scope,Rootscope,我创建了一个rootScope变量,如 $rootScope.globalData = data; $rootScope.globalData.chillerConditions.HeatSource.Value = "ST"; //Default Value $scope.chillerConditions.HeatSource.Value = 1; //Default Value 其中,data是我从api返回的值。还要创建一个范围变量,该变

我创建了一个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>
在更改下拉列表时,我编写了一个函数。在那

if($scope.chillerConditions.HeatSource.Value == 2)
{
  $rootScope.globalData.chillerConditions.HeatSource.Value = "HW";
}
else
{
  $rootScope.globalData.chillerConditions.HeatSource.Value = "ST";
}
到现在为止,这是我目前的密码。 问题是:

当调用上述函数时,只要当前
$rootScope
可变,即
$rootScope.globalData.columerconditions.HeatSource.Value
更改为
“HW”
“ST”
它也会将
$scope.columerconditions.HeatSource.Value
更改为
“HW”
“ST”

为什么会这样

angularjs中是否有内置功能?
如果我犯了什么错误,请提出建议?也欢迎新的建议。

在您的示例中,您同时拥有ng型号和ng更改,因此: 1.用户在选择中更改值。 2. $范围.制冷机条件.热源.数值变化(ng型) 3.heatSourceChanged启动(ng更改)->$rootScope.globalData.ColumerConditions.HeatSource.Value更改


因此,一切都应该正常工作…

在您的示例中,您同时拥有ng模型和ng更改,因此: 1.用户在选择中更改值。 2. $范围.制冷机条件.热源.数值变化(ng型) 3.heatSourceChanged启动(ng更改)->$rootScope.globalData.ColumerConditions.HeatSource.Value更改


因此,一切都应该正常工作…

在您的示例中,您同时拥有ng模型和ng更改,因此: 1.用户在选择中更改值。 2. $范围.制冷机条件.热源.数值变化(ng型) 3.heatSourceChanged启动(ng更改)->$rootScope.globalData.ColumerConditions.HeatSource.Value更改


因此,一切都应该正常工作…

在您的示例中,您同时拥有ng模型和ng更改,因此: 1.用户在选择中更改值。 2. $范围.制冷机条件.热源.数值变化(ng型) 3.heatSourceChanged启动(ng更改)->$rootScope.globalData.ColumerConditions.HeatSource.Value更改


因此,一切都按应有的方式运行…

此行为是JavaScript的工作方式,与AngularJS无关。JavaScript是一种面向对象(基于原型)的语言,其中对象通过引用而不是值来处理。例如,将car2指定给car1,两者将引用同一对象()

因此,在您的例子中,
$rootScope.globalData.columerConditions.HeatSource
$scope.columerConditions.HeatSource
是同一个对象

相反,您似乎想要创建一个副本。你可以这样做


这种行为是JavaScript的工作方式,与AngularJS无关。JavaScript是一种面向对象(基于原型)的语言,其中对象通过引用而不是值来处理。例如,将car2指定给car1,两者将引用同一对象()

因此,在您的例子中,
$rootScope.globalData.columerConditions.HeatSource
$scope.columerConditions.HeatSource
是同一个对象

相反,您似乎想要创建一个副本。你可以这样做


这种行为是JavaScript的工作方式,与AngularJS无关。JavaScript是一种面向对象(基于原型)的语言,其中对象通过引用而不是值来处理。例如,将car2指定给car1,两者将引用同一对象()

因此,在您的例子中,
$rootScope.globalData.columerConditions.HeatSource
$scope.columerConditions.HeatSource
是同一个对象

相反,您似乎想要创建一个副本。你可以这样做


这种行为是JavaScript的工作方式,与AngularJS无关。JavaScript是一种面向对象(基于原型)的语言,其中对象通过引用而不是值来处理。例如,将car2指定给car1,两者将引用同一对象()

因此,在您的例子中,
$rootScope.globalData.columerConditions.HeatSource
$scope.columerConditions.HeatSource
是同一个对象

相反,您似乎想要创建一个副本。你可以这样做


ng型号
columperconditions.HeatSource.Value
)可能同时附加到
$scope.columperconditions.HeatSource.Value
$rootScope.columperconditions.HeatSource.Value
。因此,当选择更改时,附加到
ng model
的变量也会更改。对此不确定,但值得尝试重新命名
$scope
变量。
ng model
columerconditions.HeatSource.Value
)可能同时附加到
$scope.columerconditions.HeatSource.Value
$rootScope.columerconditions.HeatSource.Value
。因此,当选择更改时,附加到
ng model
的变量也会更改。对此不确定,但值得尝试重新命名
$scope
变量。
ng model
columerconditions.HeatSource.Value
)可能同时附加到
$scope.columerconditions.HeatSource.Value
$rootScope.columerconditions.HeatSource.Value
。因此,当选择更改时,附加到
ng model
的变量也会更改。对此不确定,但值得尝试重新命名
$scope
变量。
ng model
columerconditions.HeatSource.Value
)可能同时附加到
$scope.columerconditions.HeatSource.Value
$rootScope.columerconditions.HeatSource.Value
。因此,当选择更改时,附加到
ng model
的变量也会更改。对此不太确定,但值得尝试重新命名
$scope
变量。现在我没有将其标记为已接受,但一旦我解决了问题,就会将其标记为已接受的Ans。ThanksI理解了JSfiddel示例。现在我没有标记为已接受,但一旦我解决问题
if($scope.chillerConditions.HeatSource.Value == 2)
{
  $rootScope.globalData.chillerConditions.HeatSource.Value = "HW";
}
else
{
  $rootScope.globalData.chillerConditions.HeatSource.Value = "ST";
}
var car1 = {make: "Audi"}
var car2 = car1;
car2.make = "Toyota";
$scope.chillerAttributes = angular.copy(data.ObjCandidateListChillerAttributes);
$scope.chillerConditions = angular.copy(data.ObjCandidateListConditions);