Require function in AngularJS templates
See original GitHub issueI want use require
function inside template, there’s an example of usage:
<div data-ng-include="require('myApp/templates/directive.html')"></div>
After processing of this template by wepback, module with this template will look like this:
function(module, exports) {
var path = '/some/prefix/path/myApp/templates/directive.html';
window.angular.module('ng').run(['$templateCache', function(c) {
c.put(path, "<div data-ng-include=\"require('myApp/templates/directive.html')\"></div>")
}]);
module.exports = path;
}
But require function should be replaced by webpack_require function and the result module should be like this:
function(module, exports) {
var path = '/some/prefix/path/myApp/templates/directive.html';
window.angular.module('ng').run(['$templateCache', function(c) {
c.put(path, "<div data-ng-include=\"'" + __webpack_require__(123) + "'\"></div>")
}]);
module.exports = path;
}
Additionally, require
function can be used not only in ng-include
, ng-inline
directives, it can be used in other custom attributes also.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Tutorial: 2 - AngularJS Templates
View and Template In AngularJS, the view is a projection of the model through the HTML template. This means that whenever the model...
Read more >Function of require in angularjs
1 Answer 1 · The require takes a string name (or array of strings) of the directive(s) to pass in. · If an...
Read more >AngularJS component & templates
AngularJS components have two ways to set a template for component. By passing path with templateUrl, passing string or function thetemplate ...
Read more >AngularJS to Angular concepts: Quick reference
In AngularJS, the ng-switch directive swaps the contents of an element by selecting one of the templates based on the current value of...
Read more >Loading AngularJS Components With RequireJS After ...
Simply loading and executing the "lazy" JavaScript file will register the JavaScript components. The HTML templates, on the other hand, require ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
“ngtemplate-loader”: “1.3.1”,
/**
<ng-include
src=“‘components/header/navigation/navigation.html’”></ng-include> // WORK<ng-include
src=“‘./components/header/navigation/navigation.html’”></ng-include> // NOT WORK<ng-include
`src=“‘/components/header/navigation/navigation.html’”></ng-include> // NOT WORKproject root: src/app/components/header/navigation/navigation.html
i think you can close this issue
Closing as out of scope.