0

HTML

<div my-test="{{widget.code}}"></div>

AngularJS

.directive('myTest', function() {
    return {
        templateUrl : function(elem, attr) {
            console.log(attr.myTest);
            return  attr.myTest+'-widget.html' || 'blank-widget.html';
        }
    };
})

I have this codes above and I am trying to retrieve the value under myTest which is the value that {{widget.code}} has. I also tried to search for solutions and possible workaround [1] [2] [3], and it seems I couldn't get through the problem.

console.log(attr.myTest) always tells me {{widget.code}} but if I try to see the source it will display the value that I am needing. Can somebody point me to what solution I can do on this? Thank you!

[1] https://docs.angularjs.org/guide/directive [2] Accessing attributes from an AngularJS directive [3] http://plnkr.co/edit/wWHZG97CviYrUxmxjSOb?p=preview

Community
  • 1
  • 1
bluestella
  • 383
  • 2
  • 6
  • 17

1 Answers1

0

You might want to look at this thread which manages the templateUrl through the link phase.

Community
  • 1
  • 1
srph
  • 1,312
  • 17
  • 35