1

I'm trying to move my template from being in-line to it's own file. Everything was working before I changed from template to templateUrl

Glenn.directive('test', function($compile) {
    return {
        restrict: 'A',
        priority: 1000,
        terminal: true,
        templateUrl: function(tElement, tAttrs) {
            return ('test.html');
        },
        link: function(scope, element, attrs) {     
            attrs.$set('editable-text', 'content.' + attrs.edit + '.data');
            attrs.$set('edit', null);
            $compile(element)(scope);
        }
    }
});

test.html

{{ 'content.' + tAttrs.edit + '.data' }}

<button ng-click="' + tAttrs.edit + '_form'+ '.$show()" ng-hide="' + tAttrs.edit + '_form'+ '.$visible">edit</button>

Why isn't the tAttrs being passed to my template test.html?

2
  • Can you post JSFiddle it Plunker with your code? It's hard to tell what you're trying to do. Commented Jul 23, 2014 at 18:56
  • All I'm trying to do is pass an attribute value to my template. Commented Jul 23, 2014 at 19:31

1 Answer 1

4

I never seen this that way, i always pass an string to the templateUrl property like

...
templateUrl: './foodirective.tmpl.html'
...

You could assign the attrs from your directive element in the linking function:

myApp.directive('fooDirective', function(){
  return{
    restrict: 'E',
    scope: true,
    templateUrl: './foodirective.tmpl.html',
    link: function(scope, elem, attrs){
      // do stuff
      scope.tAttrs = attrs;
    }
  }
})

I've prepared a plunk for you.

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

2 Comments

I'm not sure why this doesn't work for me. I just get null returned on my template tAttrs.edit :(
> All I'm trying to do is pass an attribute value to my template. That's exactly what I'm doing in my example, did you check the plunk?

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.