我有一个名为services.json的文件,其中包含我从windows mongodb导出的数据库,我想将该文件导入到Ubuntu上的robomongo(连接到由npm安装的mongodb).
我是初学者,我不知道如何继续,终端使用(robomongo或Ubuntu)?
我正在尝试使用*ngFor模板内部迭代数组并使用*ngIf搜索基于键的元素.现在,当条件与键匹配时,我想打破*ngFor.我想知道angular2中是否有任何选项可以ngFor根据条件打破循环.
我通过Facebook和Whatsapp分享网址.这些消息传递应用程序倾向于以共享链接的缩略图形式生成"丰富预览".到目前为止,一切似乎都很好
但是,如果我更改链接指向的内容,那么下次与完全不同的人共享相同的链接时,更改不会反映出来!这适用于Facebook和WhatsApp中的丰富预览缩略图.我发送消息的新人仍然看到前一个用户从我那里收到的旧缩略图.
例如,以下是我发送给ALICE的带有链接的消息后,消息传递应用程序呈现的缩略图的快照:

以下是我编辑链接指向的内容后,消息传递应用程序呈现的另一个缩略图的快照.我将名称更改为Pro3并将价格更改为549并向BOB发送了一条新消息...但是BOB看到了与ALICE相同的缩略图预览!
我首选的解决方案是使用Cache-Control和Pragma标记(根据网络标准)来禁用缓存,但它似乎不起作用.
这是我的代码
'<title>' + metaData.title + '</title>' +
'<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">\n' +
'<meta http-equiv="Pragma" content="no-cache">\n' +
'<meta http-equiv="Expires" content="0">\n' +
'<meta http-equiv="refresh" content="0; url=http://my.site.com/my/products">' +
'<meta name="description" content="' + metaData.description + '" />\n' +
'<meta property="og:type" content="product" />\n' +
'<meta property="og:title" content="' + metaData.title + '" />\n' +
'<meta property="og:description" content="' + metaData.description + '" />\n' +
'<meta property="og:image" content="' + metaData.imageUrl + '" />\n' …Run Code Online (Sandbox Code Playgroud) caching metadata meta-tags open-graph-protocol facebook-opengraph
我有这个界面,我用来阻止用户离开页面
export interface ComponentCanDeactivate {
canDeactivate: () => boolean;
}
@Injectable()
export class PendingChangesGuard implements CanDeactivate<ComponentCanDeactivate> {
canDeactivate(component: ComponentCanDeactivate): boolean {
return component.canDeactivate() ?
//code : //more code
}
}
Run Code Online (Sandbox Code Playgroud)
在我的一个组件中,我有以下代码
export class DashboardComponent implements ComponentCanDeactivate{
@HostListener('window:beforeunload')
canDeactivate(): boolean {
return !this.isDirty;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是来自PendingChangesGuard的我的组件 - >(component:ComponentCanDeactivate)总是为空,所以我得到一个错误说
无法调用null的canDeactivate()
我的路由也有这个设置
path: 'dashboard',
canDeactivate: [PendingChangesGuard],
loadChildren: './views/dashboard/dashboard.module#DashboardModule'
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我做错了什么?
下面是与 3 个变量一起使用的输入装饰器,并为每个变量分配了默认值
@Input() score: number = 0;
@Input() text: string = 'test';
@Input() color: string = 'red';
Run Code Online (Sandbox Code Playgroud)
这就是我将值传递给 ngFor 内的组件的方式。
[text]="item.name"
[score]="item.score"
[color]="item.color"
Run Code Online (Sandbox Code Playgroud)
如果我的 item 对象不包含color 属性,则组件中的颜色变量应采用“红色”作为默认值。
但是当我将其记录为:
ngOnInit() {
console.log(this.score, this.text, this.color);
}
Run Code Online (Sandbox Code Playgroud)
然后颜色变量将undefined作为值。
这是上述日志的控制台
8 "English" undefined
6 "Spanish" "blue"
Run Code Online (Sandbox Code Playgroud)
第一个日志是当项目不包含颜色属性时,第二个是当它包含值为蓝色的属性颜色时
使用Ionic 4创建混合应用程序时,最好使用Angular Lifecycle Hook或Ionic Lifecycle Hook专门用于初始化?
角生命周期挂钩-ngOnInit
ngOnInit() {
this.getData();
}
Run Code Online (Sandbox Code Playgroud)
离子生命周期挂钩-ionViewWillEnter
ionViewWillEnter() {
this.getData();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 abortcontroller 取消自定义反应挂钩内的获取请求,如下所示:
useEffect(() => {
const controller = new AbortController();
const { signal } = controller;
const fetchData = async () => {
try {
setState({ status: 'pending', data: null, error: null });
const response = await fetch(url, {
signal,
...options,
});
// if response is an HTTP error like 4XX 5XX
if (!response.ok) {
throw new Error(response.statusText);
}
// if response is 2XX
const data = (await response.json()) as T;
setState({ status: 'resolved', data, error: null });
} …Run Code Online (Sandbox Code Playgroud) 在我的代码库中,有使用创建的各种 Axios 实例
axios.create()
Run Code Online (Sandbox Code Playgroud)
因为我的应用程序中使用了多个基本 URL。因此,根据 baseURL 我们创建了一个相应的 Axios 实例。
现在在 App.js 文件中,我包含了 2 个拦截器
axios.interceptors.response.use(
config => {
return config;
},
error => {
if (error && error.response.status === 401) {
signOut();
}
return Promise.reject(error);
}
);
Run Code Online (Sandbox Code Playgroud)
但所有的API调用都绕过了上述2个拦截器。
我想使用上述拦截器作为我项目中所有 Axios 实例的全局拦截器。
哪个是更优化的方式.filter() + .map()或.forEach()?
这是一个示例对象数组:
var personnel = [
{
id: 5,
name: "Luke Skywalker",
pilotingScore: 98,
shootingScore: 56,
isForceUser: true,
},
{
id: 82,
name: "Sabine Wren",
pilotingScore: 73,
shootingScore: 99,
isForceUser: false,
},
{
id: 22,
name: "Zeb Orellios",
pilotingScore: 20,
shootingScore: 59,
isForceUser: false,
},
{
id: 15,
name: "Ezra Bridger",
pilotingScore: 43,
shootingScore: 67,
isForceUser: true,
},
{
id: 11,
name: "Caleb Dume",
pilotingScore: 71,
shootingScore: 85,
isForceUser: true,
},
];
Run Code Online (Sandbox Code Playgroud)
假设我们想要获得仅给出名称和 ID …