1

I have a little directive and I have troubles to make it working.

here is my directive :

angular
.module('thermofluor')
.directive('myCustomer', function() {

    return {
        restrict: 'E',
        template: 'table_plate.html'
    };
});

The template is just a paragraph with "Test" inside.

In my main HTML in call the directive with this :

<my-customer></my-customer>

but nothing appear on the screen, and in the html the directive is not replace with the directives output html

The template have the same name and is in the same folder.

What am I doing wrong ?

Thanks.

3
  • create a plnkr demo Commented Jun 29, 2018 at 12:58
  • I don't know if there is all the things, i'm working on a project where other person works (i try to remake my problem) but here it works ... : embed.plnkr.co/c3PIZnwxj5aZrkzrpC02 Commented Jun 29, 2018 at 13:04
  • are you running the code in a local server? Commented Jun 29, 2018 at 13:43

2 Answers 2

2

It should be templateUrl

return {
        restrict: 'E',
        templateUrl: 'table_plate.html'
    };
Sign up to request clarification or add additional context in comments.

4 Comments

Yes that's a mistake, i change but still the same problem :/
I make a plunkr too and this is working, I have exactly the same code in my app, so I really don't understand what is going on
No, i'm on that since 3 hours now and I can't make it working :/
this is strange, i have the exact same code but instead of showing the template there is the directive tag, the directive don't load
0

If you only need the template to show, you can use ng-include instead directive:

<ng-include
  src="string"
  [onload="string"]
  [autoscroll="string"]>
...
</ng-include>

There is also the version for any element available:

<ANY
  ng-include="string"
  [onload="string"]
  [autoscroll="string"]>
...
</ANY>

For even more info glance on https://docs.angularjs.org/api/ng/directive/ngInclude

Under either src or ng-include put the reference to the template you wish to load (depending on what version you use). For only 1 restrict it's kinda overkill to use a directive, rest you get from this approach as well.

NOTE: in above definitions, attributes in brackets are not needed for your example.

1 Comment

I need a directive (i'll have a complexe template with some values who are changing by the users actions), but I still can't make it working

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.