angular-cn/aio/dist/generated/docs/api/service-worker/SwRegistrationOptions.json

5 lines
9.8 KiB
JSON

{
"id": "api/service-worker/SwRegistrationOptions",
"title": "SwRegistrationOptions",
"contents": "\n\n<article>\n <div class=\"breadcrumb-container\">\n <div class=\"breadcrumb\">\n <script type=\"application/ld+json\">\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"BreadcrumbList\",\n \"itemListElement\": [\n { \"@type\": \"ListItem\", \"position\": 1, \"item\": { \"@id\": \"https://angular.io//api\", \"name\": \"API\" } },\n { \"@type\": \"ListItem\", \"position\": 2, \"item\": { \"@id\": \"https://angular.io/api/service-worker\", \"name\": \"@angular/service-worker\" } },\n { \"@type\": \"ListItem\", \"position\": 3, \"item\": { \"@id\": \"https://angular.io/api/service-worker/SwRegistrationOptions\", \"name\": \"SwRegistrationOptions\" } }\n ]\n }\n </script>\n <a href=\"/api\">API</a> > <a href=\"api/service-worker\">@angular/service-worker</a>\n </div>\n <div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/packages/service-worker/src/module.ts?message=docs(service-worker)%3A%20describe%20your%20change...#L17-L76\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n <a href=\"https://github.com/angular/angular/tree/12.0.0-next.7/packages/service-worker/src/module.ts#L17-L76\" aria-label=\"View Source\" title=\"View Source\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">code</i></a>\n</div>\n </div>\n \n <header class=\"api-header\">\n <h1 id=\"swregistrationoptions\">SwRegistrationOptions<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/service-worker/SwRegistrationOptions#swregistrationoptions\"><i class=\"material-icons\">link</i></a></h1>\n \n <label class=\"api-type-label class\">class</label>\n \n \n \n </header>\n \n <aio-toc class=\"embedded\"></aio-toc>\n\n <div class=\"api-body\">\n \n <section class=\"short-description\">\n <p>Token that can be used to provide options for <code><a href=\"api/service-worker/ServiceWorkerModule\" class=\"code-anchor\">ServiceWorkerModule</a></code> outside of\n<code><a href=\"api/service-worker/ServiceWorkerModule#register\" class=\"code-anchor\">ServiceWorkerModule.register()</a></code>.</p>\n\n <p><a href=\"api/service-worker/SwRegistrationOptions#description\">See more...</a></p>\n </section>\n \n \n \n <section class=\"class-overview\">\n<code-example language=\"ts\" hidecopy=\"true\">\nabstract class <a href=\"api/service-worker/SwRegistrationOptions\" class=\"code-anchor\">SwRegistrationOptions</a> {\n <a class=\"code-anchor\" href=\"api/service-worker/SwRegistrationOptions#enabled\"><span class=\"member-name\">enabled</span>?: boolean</a>\n <a class=\"code-anchor\" href=\"api/service-worker/SwRegistrationOptions#scope\"><span class=\"member-name\">scope</span>?: string</a>\n <a class=\"code-anchor\" href=\"api/service-worker/SwRegistrationOptions#registrationStrategy\"><span class=\"member-name\">registrationStrategy</span>?: string | (() => Observable&#x3C;unknown>)</a>\n}\n</code-example>\n\n \n \n\n</section>\n\n\n \n\n \n \n<section class=\"description\">\n <h2 id=\"description\">Description<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/service-worker/SwRegistrationOptions#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>You can use this token to define a provider that generates the registration options at runtime,\nfor example via a function call:</p>\n<code-example path=\"service-worker/registration-options/module.ts\" region=\"registration-options\" header=\"app.module.ts\">\nimport {<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>} from '@angular/core';\nimport {<a href=\"api/platform-browser/BrowserModule\" class=\"code-anchor\">BrowserModule</a>} from '@angular/platform-browser';\nimport {<a href=\"api/service-worker/ServiceWorkerModule\" class=\"code-anchor\">ServiceWorkerModule</a>, <a href=\"api/service-worker/SwRegistrationOptions\" class=\"code-anchor\">SwRegistrationOptions</a>} from '@angular/service-worker';\n/* . . . */\n\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n/* . . . */\n imports: [\n <a href=\"api/platform-browser/BrowserModule\" class=\"code-anchor\">BrowserModule</a>,\n ServiceWorkerModule.register('ngsw-worker.js'),\n ],\n providers: [\n {\n provide: <a href=\"api/service-worker/SwRegistrationOptions\" class=\"code-anchor\">SwRegistrationOptions</a>,\n useFactory: () => ({enabled: location.search.includes('sw=true')}),\n },\n ],\n})\nexport class AppModule {\n}\n\n</code-example>\n\n \n</section>\n\n \n\n\n\n\n\n\n\n\n<section class=\"instance-properties\">\n <h2 id=\"properties\">Properties<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/service-worker/SwRegistrationOptions#properties\"><i class=\"material-icons\">link</i></a></h2>\n <table class=\"is-full-width list-table property-table\">\n <thead>\n <tr>\n <th>Property</th>\n <th>Description</th>\n </tr>\n </thead>\n <tbody>\n \n <tr class=\"instance-property\">\n <td>\n <a id=\"enabled\"></a>\n <code class=\"\"><span class=\"member-name\">enabled</span>?: boolean</code>\n </td>\n <td>\n \n <p>Whether the ServiceWorker will be registered and the related services (such as <code><a href=\"api/service-worker/SwPush\" class=\"code-anchor\">SwPush</a></code> and\n<code><a href=\"api/service-worker/SwUpdate\" class=\"code-anchor\">SwUpdate</a></code>) will attempt to communicate and interact with it.</p>\n\n <p>Default: true</p>\n\n </td>\n </tr>\n \n <tr class=\"instance-property\">\n <td>\n <a id=\"scope\"></a>\n <code class=\"\"><span class=\"member-name\">scope</span>?: string</code>\n </td>\n <td>\n \n <p>A URL that defines the ServiceWorker's registration scope; that is, what range of URLs it can\ncontrol. It will be used when calling\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register\">ServiceWorkerContainer#register()</a>.</p>\n\n \n </td>\n </tr>\n \n <tr class=\"instance-property\">\n <td>\n <a id=\"registrationStrategy\"></a>\n <code class=\"\"><span class=\"member-name\">registrationStrategy</span>?: string | (() => Observable&#x3C;unknown>)</code>\n </td>\n <td>\n \n <p>Defines the ServiceWorker registration strategy, which determines when it will be registered\nwith the browser.</p>\n\n <p>The default behavior of registering once the application stabilizes (i.e. as soon as there are\nno pending micro- and macro-tasks) is designed to register the ServiceWorker as soon as\npossible but without affecting the application's first time load.</p>\n<p>Still, there might be cases where you want more control over when the ServiceWorker is\nregistered (for example, there might be a long-running timeout or polling interval, preventing\nthe app from stabilizing). The available option are:</p>\n<ul>\n<li><code>registerWhenStable:&#x3C;timeout></code>: Register as soon as the application stabilizes (no pending\nmicro-/macro-tasks) but no later than <code>&#x3C;timeout></code> milliseconds. If the app hasn't\nstabilized after <code>&#x3C;timeout></code> milliseconds (for example, due to a recurrent asynchronous\ntask), the ServiceWorker will be registered anyway.\nIf <code>&#x3C;timeout></code> is omitted, the ServiceWorker will only be registered once the app\nstabilizes.</li>\n<li><code>registerImmediately</code>: Register immediately.</li>\n<li><code>registerWithDelay:&#x3C;timeout></code>: Register with a delay of <code>&#x3C;timeout></code> milliseconds. For\nexample, use <code>registerWithDelay:5000</code> to register the ServiceWorker after 5 seconds. If\n<code>&#x3C;timeout></code> is omitted, is defaults to <code>0</code>, which will register the ServiceWorker as soon\nas possible but still asynchronously, once all pending micro-tasks are completed.</li>\n<li>An <a href=\"guide/observables\">Observable</a> factory function: A function that returns an <code>Observable</code>.\nThe function will be used at runtime to obtain and subscribe to the <code>Observable</code> and the\nServiceWorker will be registered as soon as the first value is emitted.</li>\n</ul>\n<p>Default: 'registerWhenStable:30000'</p>\n\n </td>\n </tr>\n \n </tbody>\n </table>\n</section>\n\n\n\n\n\n \n\n\n </div>\n</article>\n\n<!-- links to this doc:\n - api/service-worker\n - api/service-worker/ServiceWorkerModule\n - guide/service-worker-communications\n-->\n<!-- links from this doc:\n - /api\n - api/core/NgModule\n - api/platform-browser/BrowserModule\n - api/service-worker\n - api/service-worker/ServiceWorkerModule\n - api/service-worker/ServiceWorkerModule#register\n - api/service-worker/SwPush\n - api/service-worker/SwRegistrationOptions#description\n - api/service-worker/SwRegistrationOptions#enabled\n - api/service-worker/SwRegistrationOptions#properties\n - api/service-worker/SwRegistrationOptions#registrationStrategy\n - api/service-worker/SwRegistrationOptions#scope\n - api/service-worker/SwRegistrationOptions#swregistrationoptions\n - api/service-worker/SwUpdate\n - guide/observables\n - https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register\n - https://github.com/angular/angular/edit/master/packages/service-worker/src/module.ts?message=docs(service-worker)%3A%20describe%20your%20change...#L17-L76\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/service-worker/src/module.ts#L17-L76\n-->"
}