我正在寻找一种方法来开发一个菜单,通过在当前屏幕的左侧滑动可以看到.一个例子是Firefox的移动版本,当您在左侧滑动时,您可以访问当前选项卡导航,但主页面仍然可见.它被称为边栏我认为:
一种可行的方法是使用ViewFlipper,我想,但也许有更容易和更有效的可能性?我担心水平和垂直处理滚动可能有点困难......
谢谢你的回答,
Maxetx.
我正在尝试对从另一个服务获取值(返回 Promise)的服务进行单元测试,然后执行 http GET 请求。
我正在使用来自@angular/common/http/testing 的 HttpTestingController 来模拟 http 请求。这是测试和生产代码:
测试.service.spec.ts
it('should get base url from indexedDb then execute http get request', (async () => {
fakeParametresService.getBaseUrl.and.returnValue(Promise.resolve({valeur: 'http://host:port'}));
testedService.get<any>('/endpoint').then((response: any) => {
expect(response.key).toBe('value');
});
await http.expectOne('http://host:port/endpoint').flush({key: 'value'});
http.verify();
}));
Run Code Online (Sandbox Code Playgroud)
测试服务.ts
async get<T>(endpoint: string): Promise<T> {
const baseUrl = await this.parametresService.getBaseUrl();
return this.http.get<T>(`${baseUrl.valeur}${endpoint}`).toPromise();
}
Run Code Online (Sandbox Code Playgroud)
似乎无法以这种方式模拟嵌套在 Promise 中的 http 请求。但也许这是我的误解。
我使用@angular/service-worker模块生成了一个 service-worker 来缓存我的 Angular 7 应用程序的所有静态资产,它运行良好(在 chrome 开发工具的网络选项卡中,这些文件被标记为from ServiceWorker)。
我想要做的是向从外部 API 获取的数据添加缓存支持(和后台同步)。我知道该@angular/service-worker模块支持dataGroups资产类型,但我想做一些更复杂的事情:首先提供缓存数据,然后通过网络获取数据,更新缓存,最后返回第二个更新鲜的响应。这个想法在离线食谱中有所描述:https : //developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-then-network
所以我需要添加一个与一个由 Angular 生成。问题是我的fetch事件侦听器从未被触发。
我注册了我的服务工作者:
ServiceWorkerModule.register('../sw.js', { enabled: environment.production }),在 app.module.ts 中。
sw.js 文件导入 ngsw-worker.js(由 Angular 生成):
importScripts('./ngsw-worker.js');
importScripts('./sw-custom.js');
Run Code Online (Sandbox Code Playgroud)
然后,sw-custom.js在install和上添加两个事件侦听器fetch:
self.addEventListener('install', function(event) {
try {
console.log('typeof System in install', typeof System);
} catch(e){}
console.log('caching');
event.waitUntil(
caches.open(CACHE_VERSION).then(function(cache) {
console.log('caching - getting');
return;
}).catch(function(error){ console.log('error', error) })
);
});
self.addEventListener('fetch', event …Run Code Online (Sandbox Code Playgroud) service-worker progressive-web-apps angular angular-service-worker