angular中的$q.defer()服務(wù)異步處理

jquery和angular都有defer服務(wù),我暫以angular為例談?wù)勎业睦斫?,最后并附上jquery的阮一峰總結(jié)的defer。

以我目前項目的部分代碼為例說明為什么要用deferred。

復(fù)制代碼
function getBase64(img){//傳入圖片路徑,返回base64 function getBase64Image(img,width,height) { var canvas = document.createElement("canvas");
               canvas.width = width ? width : img.width;
               canvas.height = height ? height : img.height; var ctx = canvas.getContext("2d");
               ctx.drawImage(im
        
		

網(wǎng)友評論