我正在使用Angular 2和Typescript,并希望将用户对象保存为全局变量,因此不能多次检索它.我找到了会话存储,现在将用户对象保存在那里.
你认为将它存储在那里是好的做法还是数据过于敏感?如果是这样,我可以使用哪种其他类型的缓存?
这是我现在使用的代码:
user.service.ts:
getProfile() {
let cached: any;
if (cached = sessionStorage.getItem(this._baseUrl)) {
return Observable.of(JSON.parse(cached));
} else {
return this.http.get(this._baseUrl).map((response: Response) => {
sessionStorage.setItem(this._baseUrl, response.text());
return response.json();
});
}
}
Run Code Online (Sandbox Code Playgroud)
当ngOnInit()时,在app.component中调用getProfile().应用程序的其他组件也需要用户对象.
我对定义的类型有疑问,并检查该类型中是否包含值。
这是我的示例:
这些类型是:
export type Key = 'features' | 'special';
export type TabTypes = 'info' | 'features' | 'special' | 'stars';
Run Code Online (Sandbox Code Playgroud)
当用户更改选项卡时,它会从Type of TabTypes发送一个字符串值。
activeTabChanged(event: TabTypes) {
this.activeTab: TabTypes = event;
// it won't let me set the key here because key has a different type
// but the send event can be contained in type Key
// how can I check if the send event from type TabTypes is contained in type Key
this.key: Key = event;
}
Run Code Online (Sandbox Code Playgroud)
有没有一种打字稿方法来检查带有类型的发送值是否可以等于来自其他类型的值?
我想设置永远监视器.
我把它添加到我的app.js:
var forever = require('forever-monitor');
var child = new(forever.Monitor)('app.js', {
max: 3,
silent: true,
options: []
});
child.on('exit', function() {
console.log('app.js has exited after 3 restarts');
});
child.start();
Run Code Online (Sandbox Code Playgroud)
但是,当我从命令行启动我的应用程序时,它记录'app.js已经在3次启动后退出'但它仍然运行.该代码应放在哪个文件中?我错过了关于forever-monitor的使用方法吗?
我正在寻找一个具有自动格式化ejs文件功能的包.我已经安装了HTMLPrettify.是否可以将ejs添加为html格式,以便将其格式化为html代码?这对我来说已经足够了.
angular ×2
typescript ×2
ejs ×1
forever ×1
format ×1
node.js ×1
storage ×1
sublimetext2 ×1
types ×1