我们正在构建新的Angular 4项目,并试图了解哪种方法最适合处理全局常量,这些常量将在所有项目中重用.
我想将所有常量放在共享文件夹中,如此
共享
--constants
--dateTime.ts
--money.ts
--dialogConfig.ts
Run Code Online (Sandbox Code Playgroud)
并为每个文件使用可注入令牌
https://blog.thoughtram.io/angular/2016/05/23/opaque-tokens-in-angular-2.html
例如dialogConfig.ts将
export let DIALOG = new InjectionToken<DialogConfig>('dialog-config');
export const DIALOG_CONFIG: DialogConfig = {
width : '600px',
height : 'auto'
};
Run Code Online (Sandbox Code Playgroud)
这样每个常量对象都将从名称冲突中保存,并且可以注入.
这种方法的优点和缺点是什么?
我注意到,如果我们尝试打开https://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_number
在Windows Surface Tablet上的Chrome中,它的行为与桌面浏览器相同.我的意思是在平板电脑(移动)设备上,如果我点击,<input type="number">Chrome将显示数字键盘.但在Surface Chrome上会显示文字键盘.
此外,移动浏览器通过在用户尝试输入值时显示更适合输入数字的特殊键盘,进一步帮助提升用户体验. developer.mozilla.org
有没有办法如何强制Windows Surface上的Chrome充当移动浏览器?至少对于数字领域?
所以我们以这种方式从下拉资源模块中的下拉列表中缓存值
var cache = new CacheFactory('DropDownResource', {
maxAge: 3600000,
deleteOnExpire: 'aggressive',
capacity: 5,
storageMode: 'sessionStorage'
});
Run Code Online (Sandbox Code Playgroud)
然后在 $http 回调中,我们以这种方式保存下拉数据
cache.put('dataForDropDown', data);
Run Code Online (Sandbox Code Playgroud)
在其他模块中,我们可以更改用户设置,尤其是更改语言。在此操作之后,我需要清理缓存。因为当用户更改语言并转到带有下拉列表的页面时,他希望看到带有所需语言的下拉列表。
因此,在带有下拉列表的页面上,我们需要再次向服务器发送调用。为此,我们需要在语言更改后清理缓存。
我们怎么做?
我在下拉模块中尝试此代码。
var cache = $cacheFactory('dataForDropDown'); cache.remove('dataForDropDown');
但它不起作用。它说已经创建了名为 dataForDropDown 的缓存。我不明白我做错了什么
我有用Angular 1.5编写的遗留应用程序,我想添加用Angular 2编写的新组件
但我有ng2-translate的问题
所以这是我的组件home.ts
import {Component} from '@angular/core';
import {TranslateService, TranslateLoader, TranslateStaticLoader, TranslatePipe} from 'ng2-translate/ng2-translate';
import {Http} from '@angular/http';
@Component({
selector: 'home',
providers: [ TranslateService ],
templateUrl: './home.html'
})
export class Home {
constructor(translate: TranslateService) {
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use('en');
}
}
Run Code Online (Sandbox Code Playgroud)
这里是home.html
<h3>Home …Run Code Online (Sandbox Code Playgroud) 我的团队正在使用 Angular 1.5.* + 打字稿进行项目。
有人可以为我这样的项目提供有关最佳 TSLint 配置的建议吗?
我现在想从官方 TS 存储库和 ESlint 规则集添加 TSLint 配置(https://github.com/Microsoft/TypeScript/blob/master/tslint.json)。https://github.com/Microsoft/TypeScript/blob/master/tslint.json
就够了吗?你怎么认为?
预先感谢您的回答。
error TS6044: Compiler option 'types' expects an argument.尝试"types": []在tsconfig.json中设置时,我遇到以下错误.
我们正在使用grunt-ts
这是官方TS文档推荐的,以消除以下错误: node_modules/@types/angular/index.d.ts(14,9): error TS2403
指定"类型":[]禁用自动包含@types包.
但是,我没有禁用自动包含@types,而是看到了错误 error TS6044: Compiler option 'types' expects an argument.
有人能帮我吗?