天道酬勤,学无止境

angular2-opaquetoken

Angular 2不透明令牌有什么意义?(What is in Angular 2 Opaque Token and What's the Point?)

问题 我遇到“不透明令牌”作为在Angular 2中实现全局常量的解决方案,例如:在Angular 2中定义全局常量 尽管阅读了文档,但我似乎无法理解这一点。 与使用字符串作为令牌相比,使用OpaqueToken更好,因为多个提供程序使用相同的字符串作为两个不同的令牌可能会引起冲突。 什么? 首先是什么Angular2代币? 我在Google上所获得的只是关于JSON Web令牌(它们在auth等角色中的作用)的答案,据我了解,但显然没有任何关系。 什么是不透明令牌? 它是干什么用的? PS用于提供常量的不透明标记的更多文档。 但是,他们对我没有太大帮助。 回答1 更新Angular4 在Angular4中,不推荐使用OpaqueToken并将其替换为InjectionToken 。 InjectionToken允许传递通用类型参数。 export let APP_CONFIG = new InjectionToken<MyConfig>("app.config"); 也可以看看 https://blog.thoughtram.io/angular/2016/05/23/opaque-tokens-in-angular-2.html https://angular.io/docs/ts/latest/api/core/index/OpaqueToken-class.html

2021-04-16 00:16:51    分类:技术分享    angular   angular2-opaquetoken

What is in Angular 2 Opaque Token and What's the Point?

I am running into 'opaque tokens' as a solution to implementing global constants in Angular 2, for example here: Define global constants in Angular 2 Despite reading the docs, I can't seem to grasp the point. Using an OpaqueToken is preferable to using strings as tokens because of possible collisions caused by multiple providers using the same string as two different tokens. What? What's an Angular2 token to begin with? All I get on google are answers on JSON Web Tokens (their role in auth, etc, etc), which I understand, but are obviously not related in any way. What's an Opaque Token? What is

2021-03-27 22:55:27    分类:问答    angular   angular2-opaquetoken