TypeError:非法调用--当$watch数据包含文件对象angularJS时
我有一个名为models.questions的对象,我使用$watch监视它的变化(deepwatch,监视models.questions的整个对象)。例如:TypeError:非法调用--当$watch数据包含文件对象angularJS时,angularjs,angularjs-scope,angularjs-watch,Angularjs,Angularjs Scope,Angularjs Watch,我有一个名为models.questions的对象,我使用$watch监视它的变化(deepwatch,监视models.questions的整个对象)。例如: $scope.$watch('models.questions', function (newVal, oldVal) { do sth... } <md-input-container ng-if="item.Question.Required"> <button ngf-select n
$scope.$watch('models.questions', function (newVal, oldVal) {
do sth...
}
<md-input-container ng-if="item.Question.Required">
<button ngf-select ngf-change="upload($files,$index)" multiple="multiple">Add+</button>
</md-input-container>
模型。问题可能包含以下数据:
{
"Question": {
"Description": "",
"Index": "",
"QuestionType": "StaticElement",
"tag": "This is a static element",
"originalName": "Static - Label/Link/Image",
"Title": "",
"Required": true,
"Dynamic": "",
"Dependency": "",
"Hidden": false,
"Options": [],
"displayOptions": [
"x.png"
]
},
"Dependencies": {
"RelationBetweenOptions": "",
"Action": "",
"OptionsForSelect": [],
"DependencyOptions": []
}
}
直到最近,我的代码还可以正常工作。我需要将一些文件类型对象放入“选项”中。我曾经在“选项”中输入字符串或int类型,代码可以正常工作
但一旦我把一个文件类型的对象放进去。当代码执行$watch时,我得到的错误是
angular.js:14525 TypeError: Illegal invocation
at sa (angular.js:1205)
at sa (angular.js:1189)
at sa (angular.js:1205)
at sa (angular.js:1205)
at sa (angular.js:1189)
at m.$digest (angular.js:17993)
at m.$apply (angular.js:18269)
at angular.js:20186
at e (angular.js:6274)
at angular.js:6554
文件对象是用户选择上载的文件。例如:
$scope.$watch('models.questions', function (newVal, oldVal) {
do sth...
}
<md-input-container ng-if="item.Question.Required">
<button ngf-select ngf-change="upload($files,$index)" multiple="multiple">Add+</button>
</md-input-container>
加+
上传功能如下所示:
$scope.upload = function (file, index) {
if ($scope.models.questions[index].Question.displayOptions === undefined) {
$scope.models.questions[index].Question.displayOptions = [];
}
for (var i = 0; i < file.length; i++) {
var count = 0;
var tmpFileName = file[i].name;
while ($scope.models.questions[index].Question.displayOptions.indexOf(tmpFileName) !== -1) {
tmpFileName = file[i].name + '(' + count + ')';
count++;
}
$scope.models.questions[index].Question.displayOptions.push(tmpFileName);
$scope.models.questions[index].Question.Options.push(file[i]);
}
};
$scope.upload=函数(文件、索引){
if($scope.models.questions[index].Question.displayOptions==未定义){
$scope.models.questions[index].Question.displayOptions=[];
}
对于(var i=0;i
我不知道如何调试这个。有人知道是什么导致了这个错误吗?
谢谢。你能举个例子说明你正在创建什么类型的文件对象以及它们是如何放入选项数组的吗?你是在进行深度监视还是浅层监视?我更新了问题,解释了如何获取文件对象以及如何将它们放入选项数组。我在监视模型的整个对象。问题,我相信这是深度监视?很抱歉,我刚开始angularJs开发3个月。