Is there a way to pass a templateUrl
to my directive. I understand I can use transclusion, but that seems too much. For example, I have a widget
directive that I want to fill with specific html. Is there a way to pass it in like:
<div widget templateUrl="template1.html"></div>
<div widget templateUrl="template2.html"></div>
templateUrl can also be a function which returns the URL of an HTML template to be loaded and used for the directive. AngularJS will call the templateUrl function with two parameters: the element that the directive was called on, and an attr object associated with that element.
ng-state is not an AngularJS directive. Q 15 - Which of the following is true about ng-app directive? A - ng-app directive defines and links an AngularJS application to HTML.
Answer:The link option is just a shortcut to setting up a post-link function. controller: The directive controller can be passed to another directive linking/compiling phase. It can be injected into other directices as a mean to use in inter-directive communication.
If this is a fixed URL you can define a directive such as
app.directive('myDirective', function() {
return {
templateUrl: function(tElement, tAttrs) {
return tAttrs.templateUrl;
}
};
});
then use it like this
<div my-directive template-url="template1.html"></div>
Otherwise you could pass the URL as you would pass any other attribute into a directive and use ng-include
in your directive's template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With