0
我有離子選項卡里面的離子選項卡。當我嘗試使用畫布時document.getElementbyId裏面的離子選項卡
document.getElementById('photoCanvas');
我得到'未定義'。這是我的代碼:
HTML:
<ion-view name="photo" ng-init="loadPhotoToCanvas()">
<ion-tabs class="tabs-icon-left">
<ion-tab title="Image" icon-on="ion-image" icon-off="ion-image">
<ion-scroll delegate-handle="photoScroll" zooming="true" direction="xy" style="width: 100%; height: 40em;">
<canvas id="photoCanvas" on-touch="canvasMouseDown($event)" on-release="canvasMouseUp($event)" on-drag="canvasMouseMove($event)">
</canvas>
</ion-scroll>
</ion-tab>
</ion-tabs>
</ion-view>
控制器:
$scope.loadPhotoToCanvas = function(){
$scope.canvas = document.getElementById('photoCanvas');
//etc...
};
$ scope.canvas這裏是不確定的。
如果我把canvas放在ion-tabs指令之外,那麼getElementById就可以工作。這是工作的html:
<ion-view name="photo" ng-init="loadPhotoToCanvas()">
<ion-scroll delegate-handle="photoScroll" zooming="true" direction="xy" style="width: 100%; height: 40em;">
<canvas id="photoCanvas" on-touch="canvasMouseDown($event)" on-release="canvasMouseUp($event)" on-drag="canvasMouseMove($event)">
</canvas>
</ion-scroll>
</ion-view>
我相信這個問題是主題相關的離子標籤指令。我如何從離子選項卡獲取畫布?這種方法在概念上有錯嗎?