1

In angular I know how to create custom directives that have the following syntax:

Element directive

<my-custom-element attr1 = "some stuff"> </my-custom-element>

Attribute directive

<div my-custom-attribute> </div>

What I want to do

<div my-custom-attribute = "some value"> </div>

Is this possible?

If so, how? I would appreciate a minimalist example.

Thanks

1 Answer 1

4

You can have both named same,

app.directive('myCustomAttribute', function() {
    return {
        restrict: 'A',
        scope: {
            myCustomAttribute: '='
        },
        templateUrl: '...'
    };
});

which can be used as,

<div my-custom-attribute="somevalue"></div>

sample working example

Sign up to request clarification or add additional context in comments.

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.