久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='jpjIR'><tr id='jpjIR'><dt id='jpjIR'><q id='jpjIR'><span id='jpjIR'><b id='jpjIR'><form id='jpjIR'><ins id='jpjIR'></ins><ul id='jpjIR'></ul><sub id='jpjIR'></sub></form><legend id='jpjIR'></legend><bdo id='jpjIR'><pre id='jpjIR'><center id='jpjIR'></center></pre></bdo></b><th id='jpjIR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jpjIR'><tfoot id='jpjIR'></tfoot><dl id='jpjIR'><fieldset id='jpjIR'></fieldset></dl></div>
    <bdo id='jpjIR'></bdo><ul id='jpjIR'></ul>

  1. <legend id='jpjIR'><style id='jpjIR'><dir id='jpjIR'><q id='jpjIR'></q></dir></style></legend>

    <tfoot id='jpjIR'></tfoot>

      <small id='jpjIR'></small><noframes id='jpjIR'>

      在 Ionic 2/Angular 2 beta 10 中訪問窗口對象

      Accessing window object in Ionic 2 / Angular 2 beta 10(在 Ionic 2/Angular 2 beta 10 中訪問窗口對象)
    1. <small id='DQz9X'></small><noframes id='DQz9X'>

            <tbody id='DQz9X'></tbody>
        • <tfoot id='DQz9X'></tfoot>
            • <bdo id='DQz9X'></bdo><ul id='DQz9X'></ul>
              <i id='DQz9X'><tr id='DQz9X'><dt id='DQz9X'><q id='DQz9X'><span id='DQz9X'><b id='DQz9X'><form id='DQz9X'><ins id='DQz9X'></ins><ul id='DQz9X'></ul><sub id='DQz9X'></sub></form><legend id='DQz9X'></legend><bdo id='DQz9X'><pre id='DQz9X'><center id='DQz9X'></center></pre></bdo></b><th id='DQz9X'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DQz9X'><tfoot id='DQz9X'></tfoot><dl id='DQz9X'><fieldset id='DQz9X'></fieldset></dl></div>

              <legend id='DQz9X'><style id='DQz9X'><dir id='DQz9X'><q id='DQz9X'></q></dir></style></legend>

                本文介紹了在 Ionic 2/Angular 2 beta 10 中訪問窗口對象的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                在 Angular 1.x 和 Ionic 1.x 中,我可以通過依賴注入訪問窗口對象,如下所示:

                In Angular 1.x and Ionic 1.x I could access the window object through dependency injection, like so:

                angular.module('app.utils', [])
                
                .factory('LocalStorage', ['$window', function($window) {
                    return {
                        set: function(key, value) {
                          $window.localStorage[key] = value;
                        },
                        get: function(key, defaultValue) {
                          return $window.localStorage[key] || defaultValue;
                        }
                    };
                }]);
                

                我怎樣才能在 Angular 2 中做同樣的事情?離子 2?

                How can I do the same in Angular 2 & Ionic 2?

                推薦答案

                您可以在不導入任何內容的情況下使用 window 對象,只需在您的打字稿代碼中使用它即可:

                You can use the window object without importing anything, but by just using it in your typescript code:

                import { Component } from "@angular/core";
                
                @Component({
                     templateUrl:"home.html"
                })
                export class HomePage {
                
                  public foo: string;
                
                  constructor() {
                    window.localStorage.setItem('foo', 'bar');
                
                    this.foo = window.localStorage.getItem('foo');
                  }
                }
                

                您還可以將 window 對象包裝在服務中,以便您可以模擬它以進行測試.

                You could also wrap the window object inside a service so then you can mock it for testing purposes.

                一個簡單的實現是:

                import { Injectable } from '@angular/core';
                
                @Injectable()
                export class WindowService {
                  public window = window;
                }
                

                然后,您可以在引導應用程序時提供它,以便它在任何地方都可用.

                You can then provide this when bootstrapping the application so it's available everywhere.

                import { WindowService } from './windowservice';
                
                bootstrap(AppComponent, [WindowService]);
                

                只需在您的組件中使用它.

                And just use it in your components.

                import { Component } from "@angular/core";
                import { WindowService } from "./windowservice";
                
                @Component({
                     templateUrl:"home.html"
                })
                export class HomePage {
                
                  public foo: string;
                
                  constructor(private windowService: WindowService) {
                    windowService.window.localStorage.setItem('foo', 'bar');
                
                    this.foo = windowService.window.localStorage.getItem('foo');
                  }
                }
                

                更復雜的服務可以包裝方法和調用,因此使用起來更愉快.

                A more sophisticated service could wrap the methods and calls so it's more pleasant to use.

                這篇關于在 Ionic 2/Angular 2 beta 10 中訪問窗口對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)
                Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創建使用 Ionic 組件的自定義指令?)
                Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - Angular 2 amp;離子2)

                <small id='PrP6m'></small><noframes id='PrP6m'>

                <i id='PrP6m'><tr id='PrP6m'><dt id='PrP6m'><q id='PrP6m'><span id='PrP6m'><b id='PrP6m'><form id='PrP6m'><ins id='PrP6m'></ins><ul id='PrP6m'></ul><sub id='PrP6m'></sub></form><legend id='PrP6m'></legend><bdo id='PrP6m'><pre id='PrP6m'><center id='PrP6m'></center></pre></bdo></b><th id='PrP6m'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PrP6m'><tfoot id='PrP6m'></tfoot><dl id='PrP6m'><fieldset id='PrP6m'></fieldset></dl></div>
                  <tbody id='PrP6m'></tbody>

                    <bdo id='PrP6m'></bdo><ul id='PrP6m'></ul>
                  • <tfoot id='PrP6m'></tfoot>

                        <legend id='PrP6m'><style id='PrP6m'><dir id='PrP6m'><q id='PrP6m'></q></dir></style></legend>
                          主站蜘蛛池模板: 欧美一区二区三区在线观看视频 | 欧美在线观看网站 | 中文字幕亚洲一区 | 9久久婷婷国产综合精品性色 | 成人久久18免费网站图片 | 色欧美综合 | 日韩av在线不卡 | 夜夜夜操 | 色视频免费| 亚洲免费视频网址 | 国产成人在线播放 | 亚洲一区精品在线 | 精品综合网 | 日韩久久久久久 | 91精品久久久久久久99 | 国产成人综合在线 | av手机免费在线观看 | 久久免费视频在线 | 一区二区三区免费 | 人人玩人人添人人澡欧美 | 喷水毛片 | 国产欧美日韩综合精品一区二区 | 一道本视频 | 中文字幕亚洲免费 | 高清亚洲| 日韩午夜在线播放 | 久久久精彩视频 | 午夜精品久久久久久久99黑人 | 夜夜草天天草 | 欧美精品一区在线 | 久草新视频 | 成人网址在线观看 | 欧美激情在线精品一区二区三区 | 亚洲久草 | 久久久久久久久久久福利观看 | 国产一区二区三区四区三区四 | 91av在线看| 午夜电影在线播放 | 精品久久香蕉国产线看观看亚洲 | 欧美成年黄网站色视频 | 91视频正在播放 |