Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

templateUrl with function, hardcoded $element and $attrs #13526

Closed
@poshest

Description

@poshest

I'm trying to use an element

<comp tplsuffix="{{user.lang}}"></comp>

and in the .component definition use the function form of templateUrl to add the tplsuffix to the end of the template url, thus

bindings: {
       "tplsuffix": '='
    },
 templateUrl: function ($element, $attrs) {
      return 'home.html' + $attrs.tplsuffix;
    }

My problems are

  1. I have to literally use the variables $element and $attrs or the .component blows up. I imagine this means that minifying will kill this functionality, and it seems ['$element', '$attrs', function ... ] notation isn't allowed here.
  2. When I call $attrs.tplsuffix I get the non-interpolated version of the string "{{user.lang}}" instead of the value of that variable.

The relevant documentation in rc0 doesn't discuss how to use this nor give a templateUrl function example.

           *      If `template` is a function, then it is {@link auto.$injector#invoke injected} with
           *      the following locals:
           *
           *      - `$element` - Current element
           *      - `$attrs` - Current attributes object for the element
           *
...
           *      If `templateUrl` is a function, then it is {@link auto.$injector#invoke injected} with
           *      the following locals:
           *
           *      - `$element` - Current element
           *      - `$attrs` - Current attributes object for the element

Is this a bug? Or wasn't this function form designed to handle my use case? Or can someone please provide the correct usage if I've just got it wrong? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions