开发者社区> 问答> 正文

angular1.26用uploadify做上传指令出现ui-router不能跳转页面?报错

 用到uploadify作为上传指令的方式来上传文件吗?现在碰到这样的问题,在IE下按钮出来后,ui-router不能正常跳转页面,地址栏的url变了 却页面没有变化。 

指令代码如下:

/**上传文件
 * <div upload id="sijiPerSelect_img" ng-model="sijiPerSelect_img"	
opts="{source_id:applyP,source:4,file_type:1,image:true,button_text:'选择图片',uid:userInfo.uid,isMsg:true,m2:false}"></div>
 * */
.directive('upload', function() {
	return {
		require: 'ngModel',
		restrict : 'A',
//		transclude: true,
//		replace : true,
		scope:{
			ngModel:'=',
			opts:"=",
        	title:"="
		},
		link : function($scope, element, attr,ngModel
				) {
			var loginToken=login_token;
			//$scope.opts.login_token.replace(/\-/g,"_");
			var url=rootPath+'/upload/';
			var parameJson={
					file_type:($scope.opts.file_type?$scope.opts.file_type:'1'),
					login_token:loginToken,appid:($scope.opts.appid?$scope.opts.appid:'0'),
					source_id:$scope.opts.source_id?$scope.opts.source_id:'',
					source:$scope.opts.source?$scope.opts.source:'',
					title:$scope.opts.title?$scope.opts.title:'',flag:$scope.opts.flag?$scope.opts.flag:'',
					uid:$scope.opts.uid?$scope.opts.uid:'',
					isMsg:($scope.opts.isMsg?$scope.opts.isMsg:false),
					m2:($scope.opts.m2!=undefined?$scope.opts.m2:true)
					};
			$("#"+element.attr("id")).uploadify({
				height        :attr.height!=undefined&&attr.height!=""?attr.height:28,
				width         :attr.width!=undefined&&attr.width!=""?attr.width:120,
				swf           :rootPath+'/s/js/uploadify/uploadify.swf',
				uploader      :rootPath+'/upload/',
				formData:parameJson,
				buttonText:$scope.opts.button_text?$scope.opts.button_text:'选择文件',//浏览文件',
				fileTypeExts:$scope.opts.image==false?attr.fileTypeExts:'*.png;*.jpg;*.jpe;*.jpeg;*.bmp;*.gif;',
				fileTypeDesc:$scope.opts.image==false?attr.fileTypeDesc:'图片文件;',
				onUploadSuccess:function(file, data, response) {
					eval("var json="+data+";");
					if(json.op_ret_code=="000"){//上传成功
						$scope.$apply(function() {
							try{
								ngModel.$setViewValue({fid:json.fid,url:json.url});
								$scope.ngModel=ngModel;
							}catch(e){
								alert(1+"\n"+e);
							}
						});
					}else{
						$scope.$apply(function(){
							try{
								if(parameJson.m2==true){
									ngModel.$setViewValue({fid:'0',url:'s/img/front/template/occupation/apply/2014_12_16/defaultUploadImg.jpg'});
								}else{
									ngModel.$setViewValue(json);
								}
								 $scope.ngModel=ngModel;
							}catch(e){
								alert(e);
							}
	                     });
					}
				},
				onUploadError:function(file,errorCode,errorMsg,errorString,swfuploadifyQueue){
				}
			});
			
		}
	}
}
)


页面模板调用上传指令如下:
<div upload id="cheduiSelect_img" ng-model="cheduiSelect_img"
						opts="{source_id:applyP,source:4,file_type:1,image:true,button_text:'选择文件'}"></div>

在IE8910下按钮能够出来 但是点击菜单不跳转页面。而地址栏是变化了。

IE控制台的报错信息如下:

在IE11下按钮出不来。

正常图:

IE11下:

在IE8910下可以上传文件但是之后出现如下异常:


展开
收起
爱吃鱼的程序员 2020-06-14 18:19:27 536 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    代码略乱

    瞟了一眼看到eval,可以用angular里面的$eval

    因为报错了,所以跳转不了页面,把错误找出来即可

    尝试把$scope.$apply的代码放在$timeout里面试试

    目前我是将浏览器的兼容性改成了IE8。而且很奇怪只有IE8才能正常。虽然报错但不收影响,而且还有一个原因是json2.js在做怪。非常感谢,我试试

    您好。

    请问这问题解决了吗?

    解决方案是什么?

    希望能学习您们的解决方案,谢谢。

    2020-06-14 18:19:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
使用TensorFlow搭建智能开发系统自劢生成App UI代码 立即下载
Fusion Design - 企业级UI解决方案揭秘 立即下载
使用TensorFlow搭建智能开发系统自动生成App UI 立即下载