Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 到底是什么触发了这种变化?_Angularjs - Fatal编程技术网

Angularjs 到底是什么触发了这种变化?

Angularjs 到底是什么触发了这种变化?,angularjs,Angularjs,我的代码包含以下HTML代码段: <div ng-repeat="wf in wos.word.wordForms"> {{ wf.statusId }} <textarea ng-change="wf.statusId = 2" ng-model="wf.definition"> </textarea> ... ... {{wf.statusId} ... ... 当我在文

我的代码包含以下HTML代码段:

<div ng-repeat="wf in wos.word.wordForms">
     {{ wf.statusId }}
     <textarea ng-change="wf.statusId = 2"
               ng-model="wf.definition">
     </textarea>
     ...
     ...

{{wf.statusId}
...
...
当我在文本区域中更改某些内容时,wf.statusId会如预期的那样变为2

现在我发出一个保存。它将当前wf内容发送到服务器。当我从服务器返回数据时,我将其复制回wf

数据已正确填充,但即使服务器返回statusId为3,我仍然可以看到HTML显示为2

(response: ng.IHttpPromiseCallbackArg<IWordForm>): any => {
   wf = angular.copy(response.data);
},
(响应:ng.ihttpromisecallbackarg):any=>{
wf=角度复制(响应数据);
},
response.data.statusId=3

当我查看页面时,我看到statusId设置为2


这是预期的行为吗?如果是这样的话,是否有任何方法可以使ng更改在我从服务器获取数据时不会将值设置为2?我只想让它在我进行用户输入时将值更改为2

我认为这是因为更新wf值时触发了
ng change
事件。在wf=angular.copy(response.data)之后添加一个超时怎么样然后将wf.statusId更改为2

守则是:

(response: ng.IHttpPromiseCallbackArg<IWordForm>): any => {
    wf = angular.copy(response.data);
    $timeout(function() {
        wf.statusId = 2;
    }, 1);
},
(响应:ng.ihttpromisecallbackarg):any=>{
wf=角度复制(响应数据);
$timeout(函数(){
wf.statusId=2;
}, 1);
},
试试看,让我知道它是否有效,我一点也不确定,但它可能有效


如果您不知道$timeout是如何工作的,请查看一下

我认为这是因为在更新wf的值时触发了
ng change
事件。在wf=angular.copy(response.data)之后添加一个超时怎么样然后将wf.statusId更改为2

守则是:

(response: ng.IHttpPromiseCallbackArg<IWordForm>): any => {
    wf = angular.copy(response.data);
    $timeout(function() {
        wf.statusId = 2;
    }, 1);
},
(响应:ng.ihttpromisecallbackarg):any=>{
wf=角度复制(响应数据);
$timeout(函数(){
wf.statusId=2;
}, 1);
},
试试看,让我知道它是否有效,我一点也不确定,但它可能有效


如果您不知道$timeout是如何工作的,请在使用超时后查看

,该值仍然没有正确设置。我不明白您为什么需要状态。此外,为什么要复制服务器返回的值?它与发送的不同吗?在使用超时后,该值仍然没有正确设置。我不明白您为什么需要状态。此外,为什么要复制服务器返回的值?它和发送的不同吗?