[英]Angular directive set element attributes
我有以下指令:
angular.module('app').directive("layer", function () {
return {
restrict: 'E',
templateUrl: 'tpl/directive/layers.html',
scope:{
width: '=',
height: '='
}
}
});
模板只是一個canvas
:
<canvas style="position: relative;" class=" " height="" width="" ></canvas>
現在,您可能已經猜到了,我希望將畫布的寬度和高度設置為等於<layer>
元素上設置的屬性
我只是不太確定如何做到這一點?
<canvas style="position: relative;" class=" " height="{{height}}" width="{{width}}" ></canvas>
您可以使用以下代碼:
<canvas style="position: relative;" class=" " height="{{height}}" width="{{width}}" ></canvas>
這很大程度上取決於您如何定義HTML以及如何編寫屬性,但是您可以像這樣實現(將畫布更改為按鈕以更清楚地說明它):
myApp.directive("layer", function () {
return {
restrict: 'E',
template: '<button style="height:{{height}}px; width: {{width}}px;" class="">This is my button</button>',
scope:{
width: '@',
height: '@'
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.