{"id":303245,"date":"2020-05-08T15:00:45","date_gmt":"2020-05-08T15:00:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303245"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303245","title":{"rendered":"Observable \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0432 Angular"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/tinkoff\/blog\/501084\/\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u043b\u0430\u0434\u0438\u043c\u0438\u0440. \u042f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0432 Tinkoff.ru.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u043b\u044f \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0414\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 RxJS.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0433\u0443\u043b\u044f\u0440 \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 RxJS \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0438 \u044f\u0441\u043d\u043e. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0438\u043b\u0438 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0438, \u043f\u0440\u043e\u043c\u0438\u0441\u044b, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u0434\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442 \u043d\u0430\u0441 \u043e\u0442\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0426\u0435\u043b\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 API, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e RxJS \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432 Observable-\u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0435. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 Geolocation API.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-b\/16\/ed\/-b16edynheltty6vrj29btlj2zq.png\"><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h3 id=\"geolocation-api\">Geolocation API<\/h3>\n<p>  <\/p>\n<blockquote><p>Geolocation API \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u0441\u044f \u043d\u0430 \u044d\u0442\u043e. \u0418\u0437 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p><\/blockquote>\n<p>\u041d\u0438\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e Geolocation API.<\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e Geolocation \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">if('geolocation' in navigator) {  \/* geolocation is available *\/  } else {  \/* geolocation IS NOT available *\/  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Geolocation\/getCurrentPosition\">getCurrentPosition()<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Geolocation\/watchPosition\">watchPosition()<\/a>, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">... success(position) {  doSomething(position.coords.latitude, position.coords.longitude); }   error() {  alert('Sorry, no position available.'); }   watch() {  this.watchID = navigator.geolocation.watchPosition(this.success, this.error); }  stopWatch() {   navigator.geolocation.clearWatch(this.watchID); } ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 clearWatch() \u0441 id \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0437\u0430 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u041e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u044d\u043d\u0435\u0440\u0433\u0438\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c. \u041d\u043e \u0442\u0430\u043a\u043e\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435\u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e RxJS Observable.<\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Geolocation, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u044d\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u043c NAVIGATOR \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/github.com\/ng-web-apis\/common\">@ng-web-apis\/common<\/a>. <\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">export const GEOLOCATION = new InjectionToken&lt;Geolocation&gt;(    'An abstraction over window.navigator.geolocation object',    {        factory: () =&gt; inject(NAVIGATOR).geolocation,    }, );<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0442\u043e\u043a\u0435\u043d, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c Geolocation API:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">export const GEOLOCATION_SUPPORT = new InjectionToken&lt;boolean&gt;(    'Is Geolocation API supported?',    {        factory: () =&gt; !!inject(GEOLOCATION),    }, );<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0442\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 PositionOptions:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">import {InjectionToken} from '@angular\/core';  export const POSITION_OPTIONS = new InjectionToken&lt;PositionOptions&gt;(    'Token for an additional position options',    {factory: () =&gt; ({})}, );<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441! Observable \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044f \u0441 Observable, \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0431\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Subscriber, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430\u043c, \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u0442 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0438\u043b\u0438 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 next(), complete() \u0438 error(). \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442: <\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">@Injectable({    providedIn: 'root', }) export class GeolocationService extends Observable&lt;Position&gt; {    constructor(        @Inject(GEOLOCATION) geolocationRef: Geolocation) {         super(subscriber =&gt; {             geolocationRef.watchPosition(                position =&gt; subscriber.next(position),                positionError =&gt; subscriber.error(positionError),            );        });    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0438 \u043e\u043f\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">@Injectable({    providedIn: 'root', }) export class GeolocationService extends Observable&lt;Position&gt; {   constructor(   @Inject(GEOLOCATION) geolocationRef: Geolocation,   @Inject(GEOLOCATION_SUPPORT) geolocationSupported: boolean,   @Inject(POSITION_OPTIONS) positionOptions: PositionOptions, ) {   super(subscriber =&gt; {     if (!geolocationSupported) {       subscriber.error('Geolocation is not supported in your browser');     }      geolocationRef.watchPosition(       position =&gt; subscriber.next(position),       positionError =&gt; subscriber.error(positionError),       positionOptions,     );    })   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0424\u0438\u043d\u0438\u0448\u043d\u0430\u044f \u043f\u0440\u044f\u043c\u0430\u044f! \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Observable, \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <em>pipe()<\/em>. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 RxJS-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0430 \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u043b\u0441\u044f \u043d\u0430 \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c RxJS-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>shareReplay()<\/em>.<br \/>  \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 <em>share()<\/em>? \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u043c Geolocation API \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 getCurrentPosition() \u0438 watchPosition() \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 <strong>Timeout expired<\/strong>. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>shareReplay()<\/em> \u0440\u0435\u0448\u0438\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0433\u0435\u043e\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0433\u0435\u043e\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0435\u0435 \u0435\u0434\u0438\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c. \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0438 <em>{bufferSize: 1, refCount: true}<\/em>, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432. \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 clearWatch()-\u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c RxJS-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>finalize()<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">@Injectable({    providedIn: 'root', }) export class GeolocationService extends Observable&lt;Position&gt; {    constructor(        @Inject(GEOLOCATION) geolocationRef: Geolocation,        @Inject(GEOLOCATION_SUPPORT) geolocationSupported: boolean,        @Inject(POSITION_OPTIONS)        positionOptions: PositionOptions,    ) {        let watchPositionId = 0;         super(subscriber =&gt; {            if (!geolocationSupported) {                subscriber.error('Geolocation is not supported in your browser');            }             watchPositionId = geolocationRef.watchPosition(                position =&gt; subscriber.next(position),                positionError =&gt; subscriber.error(positionError),                positionOptions,            );        });         return this.pipe(            finalize(() =&gt; geolocationRef.clearWatch(watchPositionId)),            shareReplay({bufferSize: 1, refCount: true}),        );    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u0433\u043e\u0442\u043e\u0432! \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0443\u0434\u043e\u0431\u043d\u043e, \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">... constructor(@Inject(GeolocationService) private readonly position$: Observable&lt;Position&gt;) {} ...    position$.pipe(take(1)).subscribe(position =&gt; doSomethingWithPosition(position)); ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f async pipe. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442\u0441\u044f \u0441 <a href=\"https:\/\/github.com\/angular\/components\/tree\/master\/src\/google-maps#readme\">@angular\/google-maps<\/a> \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u043a\u0430\u0440\u0442\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;app-map        [position]=&quot;position$ | async&quot; &gt;&lt;\/app-map&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e\u0431 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 RxJS \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Geolocation API. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/github.com\/ng-web-apis\/geolocation\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041e\u043d \u0433\u043e\u0442\u043e\u0432 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0438 <a href=\"https:\/\/www.npmjs.com\/package\/@ng-web-apis\/geolocation\">\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u0432 npm<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u0438 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 ResizeObserver API \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043c\u043e\u0436\u043d\u043e \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b.<\/p>\n<p>  <\/p>\n<h3 id=\"resizeobserver-api\">ResizeObserver API<\/h3>\n<p>  <\/p>\n<blockquote><p>API Resize Observer \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p><\/blockquote>\n<p>\u041a\u0430\u043a \u0438 Geolocation API, \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 ResizeObserver API \u043d\u0435\u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0435. \u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0433\u043e \u0432 Observable-\u0441\u0435\u0440\u0432\u0438\u0441. \u041d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u042d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0432\u044b\u0448\u0435, \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">@Injectable() export class ResizeObserverService extends Observable&lt;    ReadonlyArray&lt;ResizeObserverEntry&gt; &gt; {    constructor(        @Inject(ElementRef) {nativeElement}: ElementRef&lt;Element&gt;,        @Inject(NgZone) ngZone: NgZone,        @Inject(RESIZE_OBSERVER_SUPPORT) support: boolean,        @Inject(RESIZE_OPTION_BOX) box: ResizeObserverOptions['box'],    ) {        let observer: ResizeObserver;         super(subscriber =&gt; {            if (!support) {                subscriber.error('ResizeObserver is not supported in your browser');            }             observer = new ResizeObserver(entries =&gt; {                ngZone.run(() =&gt; {                    subscriber.next(entries);                });            });            observer.observe(nativeElement, {box});        });         return this.pipe(            finalize(() =&gt; observer.disconnect()),            share(),        );    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0430 \u0437\u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 ResizeObserver. \u041c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 next() \u0432 ngZone() \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u0442\u0430\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u0439 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 Geolocation-\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d ElementRef. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434 observe(). \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041c\u0435\u0445\u0430\u043d\u0438\u0437\u043c Dependency Injection \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441. <\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0442\u0430\u043b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u0431\u0435\u0440\u043d\u0435\u043c \u0435\u0433\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 Output(), \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">@Directive({    selector: '[waResizeObserver]',    providers: [        ResizeObserverService,        {            provide: RESIZE_OPTION_BOX,            deps: [[new Attribute('waResizeBox')]],            useFactory: boxFactory,        },    ], }) export class ResizeObserverDirective {    @Output()    readonly waResizeObserver: Observable&lt;ResizeObserverEntry[]&gt;;     constructor(        @Inject(ResizeObserverService)        entries$: Observable&lt;ResizeObserverEntry[]&gt;    ) {        this.waResizeObserver = entries$;    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a RESIZE_OPTION_BOX \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u044b \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u0446\u0438\u0438 ReziseObserver \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0433\u043e\u0442\u043e\u0432\u0430. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;div        waResizeBox=&quot;content-box&quot;        (waResizeObserver)=&quot;onResize($event)&quot;    &gt;        Resizable box &lt;\/div&gt;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"cs\">...    onResize(entry: ResizeObserverEntry[]) {        \/\/ do something with entry    } ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0436\u0435 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u043e \u0432 \u043a\u0440\u043e\u0448\u0435\u0447\u043d\u0443\u044e open-source-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f <a href=\"https:\/\/www.npmjs.com\/package\/@ng-web-apis\/resize-observer\">\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0430 npm<\/a>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/github.com\/ng-web-apis\/resize-observer\">\u043d\u0430 \u00ab\u0413\u0438\u0442\u0445\u0430\u0431\u0435\u00bb<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0430\u0440\u0441\u0435\u043d\u0430\u043b RxJS \u0438 Dependency Injection \u0434\u0430\u0436\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0438 API, \u043d\u0435 \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0434 \u0410\u043d\u0433\u0443\u043b\u044f\u0440. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043e\u0433\u0440\u0430\u0434\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u0442 \u0438\u0437\u043b\u0438\u0448\u043d\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0443\u0436\u0435 \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u0430\u043c\u0438, \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430 \u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e <a href=\"https:\/\/github.com\/ng-web-apis\/midi\/blob\/master\/projects\/midi\/src\/tokens\/midi-messages.ts\">\u0432 @ng-web-apis\/midi.<\/a> \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/www.newline.co\/@waterplea\/jam-on-your-midi-keyboard-in-angular--6c16e1e0\">\u0437\u0434\u0435\u0441\u044c<\/a>. <\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0438\u0434\u0435\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c Web APIs for Angular. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0445 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e API \u0432 Angular-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u0435\u043d, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, <a href=\"https:\/\/habr.com\/ru\/company\/tinkoff\/blog\/492700\/\">Payment Request API<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/indepth.dev\/what-makes-a-good-angular-library\">Intersection Observer<\/a>, \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/ng-web-apis.github.io\/\">\u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0440\u0435\u043b\u0438\u0437\u044b<\/a>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/tinkoff\/blog\/501084\/\"> https:\/\/habr.com\/ru\/company\/tinkoff\/blog\/501084\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/tinkoff\/blog\/501084\/\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u043b\u0430\u0434\u0438\u043c\u0438\u0440. \u042f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0432 Tinkoff.ru.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u043b\u044f \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0414\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 RxJS.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0433\u0443\u043b\u044f\u0440 \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 RxJS \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0438 \u044f\u0441\u043d\u043e. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0438\u043b\u0438 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0438, \u043f\u0440\u043e\u043c\u0438\u0441\u044b, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u0434\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442 \u043d\u0430\u0441 \u043e\u0442\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0426\u0435\u043b\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 API, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e RxJS \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432 Observable-\u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u0435. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 Geolocation API.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-b\/16\/ed\/-b16edynheltty6vrj29btlj2zq.png\"><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303245","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303245"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303245\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}