
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
ng-cache-loader
Advanced tools
Puts HTML partials in the Angular's $templateCache so directives can use templates without initial downloading.
Webpack is the webpack and it's module bundler. Loaders wrap content in the javascript code that executes in the browser.
npm install ng-cache-loader
You can require html partials via ng-cache-loader
:
require('ng-cache!./demo/template/myPartial.html');
Partial will be available as ng-include="'myPartial.html'"
or templateUrl: 'myPartial.html'
.
You can wrap template in the script
tag:
<!-- ./demo/template/myPartial.html -->
<script type ="text/ng-template" id="myFirstTemplate">
<!-- then use ng-include="'myFirstTemplate'" -->
</script>
You can have multiple templates in one file:
<!-- ./demo/template/myPartial.html -->
<script type ="text/ng-template" id="myFirstTemplate">
<!-- then use ng-include="'myFirstTemplate'" -->
</script>
<script type ="text/ng-template" id="mySecondTemplate">
<!-- then use ng-include="'mySecondTemplate'" -->
</script>
You can mix named templates and simple markup:
<!-- ./demo/template/myPartial.html -->
<script type ="text/ng-template" id="myFirstTemplate">
<!-- then use ng-include="'myFirstTemplate'" -->
</script>
<!-- markup outside script tags available as ng-include="'myPartial.html'" -->
<div ng-include="'myFirstTemplate'">...</div>
<script type ="text/ng-template" id="mySecondTemplate">
<!-- then use ng-include="'mySecondTemplate'" -->
</script>
Prefix adds path left of template name:
require('ng-cache?prefix=public/templates!./path/to/myPartial.html')
// => ng-include="'public/templates/myPartial.html'"
Prefix can mask the real directory with the explicit value
or retrieve the real directory name (use *
or [dir]
):
require('ng-cache?prefix=public/*/templates!./path/to/myPartial.html')
// => ng-include="'public/path/templates/myPartial.html'"
Prefix can strip the real directory name (use //
):
require('ng-cache?prefix=public/*//*/templates!./far/far/away/path/to/myPartial.html')
// => ng-include="'public/far/path/templates/myPartial.html'"
Prefix can be extended through a directory tree (use **
or [dirs]
). See the next section.
You can specify root directory for templates separated by a colon prefix=root:**
.
It is enough to specify a single directory. Prefix counts directories from right to left and takes rightmost occurance of the specified directory.
/User/packman/Projects/packman/
├─ app/tmpls/field.html
└─ components/skins/tmpls/yellow.html
In above example you require templates by relative path from the inside of app/tmpls
and components/skins/tmpls
,
and you get a prefix relative to the root:
require('ng-cache?prefix=packman:**!./field.html')
// => ng-include="'app/tmpls/field.html'"
require('ng-cache?prefix=packman:**!./yellow.html')
// => ng-include="'components/skins/tmpls/yellow.html'"
It is also possible to combine wildcards in prefix, i.e. prefix=packman:**/tmpls//*
.
By default, templates will be added to the default AngularJS 'ng' module run() method. Use this parameter to use a different module name:
require('ng-cache?module=moduleName!./path/to/myPartial.html')
If the module does not exist it is created.
Match .html
extension with loader:
module: {
loaders: [
{
test: /\.html$/,
loader: "ng-cache?prefix=[dir]/[dir]"
}
]
},
Relative links to the local images are resolved by default.
<!-- Source -->
<img src="../img/logo.png"></img>
<!-- becomes -->
<img src="data:image/png;base64,..."></img>
Use this in conjunction with url-loader. For instance:
require('url?name=img/[name].[ext]!ng-cache!./templates/myPartial.html')
Using webpack config is more convenience:
module: {
loaders: [
{ test: /\.html$/, loader: "ng-cache?prefix=[dir]/[dir]" },
{ test: /\.png$/, loader: 'url?name=img/[name].[ext]&mimetype=image/png' },
{ test: /\.gif$/, loader: 'url?name=img/[name].[ext]&mimetype=image/gif' }
]
},
To switch off url resolving use -url
query param:
require('ng-cache?-url!./myPartial.html')
FAQs
Puts HTML partials in the Angular's $templateCache.
The npm package ng-cache-loader receives a total of 5,514 weekly downloads. As such, ng-cache-loader popularity was classified as popular.
We found that ng-cache-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.