您可能希望看到angular-2-local-storage用於在瀏覽器的應用程序存儲中存儲數據。
從NPM註冊表:
在您的應用程序:
首先,你需要配置的服務:
import { LocalStorageService, LOCAL_STORAGE_SERVICE_CONFIG } from 'angular-2-local-storage';
// Create config options (see ILocalStorageServiceConfigOptions) for deets:
let localStorageServiceConfig = {
prefix: 'my-app',
storageType: 'sessionStorage'
};
// Provide the config to the service:
const LOCAL_STORAGE_CONFIG_PROVIDER: Provider = provide(LOCAL_STORAGE_SERVICE_CONFIG, {
useValue: localStorageServiceConfig
});
// Use the provider:
bootstrap(AppComponent, [LocalStorageService, LOCAL_STORAGE_CONFIG_PROVIDER]);
然後你就可以在組件中使用它:
import { LocalStorageService } from 'angular-2-local-storage';
@Component({
// ...
})
export class SomeComponent {
constructor (
private localStorageService: LocalStorageService
) {
// YAY!
}
}
至於谷歌驅動器支持,谷歌有一個pure JS API但他們似乎並不有一個AngularJS API,更不用說Angular2一個
乾杯!