0

I have the following directive:

angular.module('app').directive("layer", function () {
    return {
        restrict: 'E',
        templateUrl: 'tpl/directive/layers.html',
        scope:{
            width: '=',
            height: '='
        }

    }
});

The template is simply a canvas:

<canvas style="position: relative;" class=" " height="" width="" ></canvas>

Now as you might have guessed i wish to set the canvas width and height equal to the attributes set on the <layer> element

im just not quite sure how to do this?

2
  • you could use {{width}} & {{heigh}} where ever you want to set it on template 'tpl/directive/layers.html' like width="{{width+ 'px'}}" & height="{{height+ 'px'}}" Commented Jun 6, 2015 at 18:17
  • I really dont get it, you have a directive "layer" with element restriction and element you are using is canvas Commented Jun 6, 2015 at 18:17

3 Answers 3

1

You can use the following code:

<canvas style="position: relative;" class=" " height="{{height}}" width="{{width}}" ></canvas>
Sign up to request clarification or add additional context in comments.

2 Comments

Does this also work when i use '=' or should i use @?
@MarcRasmussen @ is used to access string values and = is used to create a two way binding with parent scope. It seems that in your directive you only want to pass the value to the directive, so in your case you can use either approach
1
<canvas style="position: relative;" class=" " height="{{height}}" width="{{width}}" ></canvas>

Comments

1

It pretty much depends on how you defined your HTML and how you wrote the attributes, but you can achieve it like this (changed canvas to button to illustrate it clearer):

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: '@'
        }

    }
});

Fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.