Answer the question
In order to leave comments, you need to log in
What happens in the templateUrl directive?
For the project, I put all the views into separate html files and pull them up through templateUrl.
But how and when are they loaded?
And I also have differences in structure due to templateUrl .. Using angular with requirejs breaks the harmony of the idea of angular itself. So the production will look like? app.js, style.css and a whole bunch of view.html? isn't that stupid? Or is it somehow different?
Answer the question
In order to leave comments, you need to log in
Loading occurs the first time the template is accessed.
Those. as soon as you compile a template with a directive, the template of this directive is loaded.
To eagerly load templates in production use $templateCache. The point is that when searching for a template, $templateCache is first checked for the presence of a template with the specified name (in the case of the directive name == the value of the templateUrl attribute).
If it is there, then it is simply taken from there, otherwise an attempt is made to download it.
mod.run(function($templateCahce) {
$templateCache.put('components/button/template.html', '<div></div>');
});
// Директива
return {
templateUrl: 'components/button/template.html',
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question