AngularJS 1.6.1,TypeScript,UI引导模式:为什么存储在会话存储中的全局变量会被模式更新?

AngularJS 1.6.1,TypeScript,UI引导模式:为什么存储在会话存储中的全局变量会被模式更新?,angularjs,typescript,angular-ui-bootstrap,bootstrap-modal,ng-storage,Angularjs,Typescript,Angular Ui Bootstrap,Bootstrap Modal,Ng Storage,请帮助一个新手。我正在使用ngStorage存储一些全局变量: //Global Controller saveGlobalSettings = () => { this.$sessionStorage.QuoteTimes = this.quoteTimes; this.$sessionStorage.QuoteTypes = this.quoteTypes; }; 我正在另一个控制器中使用另一种方法来创建使用某些全局变量作为属性的对象: //

请帮助一个新手。我正在使用
ngStorage
存储一些全局变量:

//Global Controller
saveGlobalSettings = () => {
        this.$sessionStorage.QuoteTimes = this.quoteTimes;
        this.$sessionStorage.QuoteTypes = this.quoteTypes;
    };
我正在另一个控制器中使用另一种方法来创建使用某些全局变量作为属性的对象:

// Create Controller 
addChannel = (channel) => {            
        channel.QuotingChannelType = channel.QuotingChannelId;             
        console.log(this.$sessionStorage.QuoteTimes);
        channel.QuoteTypes = this.$sessionStorage.QuoteTypes;
        channel.QuoteTimes = this.$sessionStorage.QuoteTimes;
        if (!this.myChannels) { this.myChannels = []; }
        this.myChannels.push(channel);           
    };
然后我使用
ng repeat
在浏览器中显示
myChannels
中的对象。单击时,我将对象传递给
openDialog()
方法:

 openPreferencesDialog = (channel) => {
        var options: ng.ui.bootstrap.IModalSettings = {
            templateUrl: 'app/form/templates/editChannelPreferences.html',
            controller: 'EditDialogController',
            controllerAs: '$ctrl',
            resolve: {
                channel: () => channel
            }
        };            
        this.$uibModal.open(options).result
            .then(updatedChannel => console.log(updatedChannel));               
    };
对话框按预期打开,但当我进行更改时,它正在更新
$sessionStorage
中的
QuoteTimes
quoteType
数组(从
添加频道中的
控制台.log
查看)。因此,创建的每个新对象都具有上次编辑的对象的
QuoteTimes
quoteType
。我完全被难住了。我最好的猜测是这是某种范围链问题?知道我做错了什么吗

更新:通过使用
JSON.parse(JSON.stringify(obj)),我能够让它按预期工作如下所示:

openPreferencesDialog = (obj, index) => {           
        var channel = JSON.parse(JSON.stringify(obj));
        var options: ng.ui.bootstrap.IModalSettings = {
            templateUrl: 'app/form/templates/editChannelPreferences.html',
            controller: 'EditDialogController',
            controllerAs: '$ctrl',
            resolve: {
                channel: () => channel
            }
        };            
        this.$uibModal.open(options).result
            .then(updatedChannel =>
            {
                console.log(updatedChannel);
                this.$sessionStorage.myChannels[index].QuoteTimes = updatedChannel.QuoteTimes;
                this.$sessionStorage.myChannels[index].QuoteTypes = updatedChannel.QuoteTypes;
                console.log(this.$sessionStorage.myChannels)
            });               
    };

有人能解释一下为什么这样做吗?

如果引用。。。通道对象的成员不是基元类型,这是正常行为。因为它们是引用类型,所以上次编辑的通道对象和$sessionstorage在内存中对它们具有相同的引用