发表于: 2017-07-07 22:44:08

1 947


今天完成的事情:终于学会了自定义指令,写了自定义指令的图片上传服务;

明天计划的事情:学会懒加载,学会常量;

遇到的问题:心态太浮躁了;

收获:1 自定义指令的写法:感觉也没多难嘛,为什么前几天学的那么痛苦?

myApp.directive("strange",["$http",function($http){

return{

restrict:"E",

templateUrl:"tpls/example3.html",

link:function(scope,element){

console.log("测试");

$("#newInput").bind("change",uploadFile);

function uploadFile(){

var file=this.files[0];

console.log(file);

var data=new FormData();

data.append("file",file);

$http({

method:"post",

url:"/carrots-admin-ajax/a/u/img/task",

headers:{'Content-Type':undefined},

data:data

}).then(function(res){

console.log(res.data.data.url);

scope.uploadSrc=res.data.data.url;

console.log("wancheng")

})

}

}

}

}])


2 $http.get(...).success is not a function 错误解决

1.6 新版本的AngularJs中用then和catch 代替了success和error,用PRomise规则。

更改写法:

复制代码

$http.get('/api/user/showname2', {

  //内容

}).then(function (result) {//正确请求成功时处理

  

  alert(result.data);

    //正确内容

}).catch(function (result) { //捕捉错误处理

  //错误内容

});



返回列表 返回列表
评论

    分享到