从您在AppModule中提供服务的Angular 5到Angular 6的更改,您在@Injectable装饰器中设置'provideIn'键我已经更改了所有服务以使用新的"provideIn"方法.但是,异常是我的拦截服务.
如何为'root'提供HTTP_INTERCEPTORS标记并使用InterceptorService?
这是我使用atm的Angular 5方式:
@Injectable()
export class InterceptorService implements HttpInterceptor {
...
}
Run Code Online (Sandbox Code Playgroud)
在AppModule中:
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: InterceptorService,
multi: true
}]
Run Code Online (Sandbox Code Playgroud)
但Angular 6的方式是什么?
我尝试过类似的东西
@Injectable({
provideIn: 'root',
useValue: HTTP_INTERCEPTORS,
deps: [forwardRef(() => InterceptorService)]
})
export class InterceptorService implements HttpInterceptor {
...
}
Run Code Online (Sandbox Code Playgroud)
还有很多其他的Injectable变种,但似乎无法弄清楚如何在不将对象文字直接写入模块的提供者的情况下使其工作.
<template>
<header>
<hamburger></hamburger>
<app-title></app-title>
<lives></lives>
</header>
</template>
<script>
export default {
name: 'Titlebar',
data() {
return {
}
}
}
</script>
<style lang="scss" scoped>
@import "../styles/variables";
header {
padding: $padding-titlebar;
position: relative;
}
lives {
position: absolute;
right: 2.5vh;
}
</style>
Run Code Online (Sandbox Code Playgroud)
是否可以像任何常规 HTML 标签一样使用组件标签来实现样式目的,就像我在 中写下的那样lives { }?
我发现在 css 中编写<lives class="lives">和使用.lives { }是可行的,但这似乎有点多余,如果可以只使用组件标签,宁愿省略添加其他类。
我知道 Vue 编译<lives>成 HTML 代码,并且编译后的 css 没有“lives”标签可供使用,但仍然想知道。
angular ×1
angular6 ×1
injectable ×1
javascript ×1
service ×1
typescript ×1
vue.js ×1
vuejs2 ×1