1

is it possible to inject string into html's tag name with angular?

Something like this:

    <div ng-repeat="type in types">
        <bettype-{{type.id}}></bettype-{{type.id}}>
    </div>

The output I need is:

<bettype-1></bettype-1>
<bettype-2></bettype-2>

I am also using polymer (this way I am creating the custom html tags).

1
  • Do you want that tag to function as an Angular directive, or is this just to be rendered and interpreted by some other engine? If the former, you'll need to call $compile on the content first, will look for a snippet to borrow. Commented Jun 19, 2014 at 12:41

1 Answer 1

2

I think the best solution would be to create a directive which creates custom elements, something like:

.directive('bettype', function($compile) {
    return {
        restrict: 'E',
        compile: function($element, $attr) {
            return function($scope, $element, $attr) {
                // Create new element here with $attr.number
                var number = $attr.number,
                    element = angular.element('<bettype-'+number+'></bettype-'+number+'>');
                // Replace newly created element
                $element.replaceWith(element);
                $compile($element)($scope);
            }
        }
    }
});

Not sure if that will work, but probably that's the way to go...

Note: I don't think it\s a good idea to have dashed separated elements like bettype-1..

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.