小编Nic*_*den的帖子

Angular Material MdSidebar-如何从打字稿中调用.toggle()

我正在尝试从另一个组件进行sidenav切换,但是当从我的父组件调用.toggle()函数时,它将引发此错误:

AppComponent.html:1错误TypeError:AppComponent.webpackJsonp.176.AppComponent.toggleNav中的this.sidenav.toggle不是函数(app.component.ts:25)

这是代码:app.component.ts

import { Component, ViewChild } from '@angular/core';
import { MaterialModule } from '@angular/material';
import { NavComponent } from './nav/nav.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { FooterComponent } from './footer/footer.component';
import { MdSidenav } from '@angular/material';
@Component({
    moduleId: module.id,
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent{
    title = 'CRS Management App';
    @ViewChild('sidenav') sidenav:MdSidenav;
    toggleNav(){
      this.sidenav.toggle();
    }
}
Run Code Online (Sandbox Code Playgroud)

app.component.html:

<app-nav #navbar (nav)="toggleNav()"></app-nav>
<app-sidebar #sidenav></app-sidebar>
<app-footer></app-footer>
Run Code Online (Sandbox Code Playgroud)

(nav)从app-nav组件发出。

sidebar.component.ts:

@Component({
  selector: 'app-sidebar',
  templateUrl: './sidebar.component.html',
  styleUrls: ['./sidebar.component.scss'] …
Run Code Online (Sandbox Code Playgroud)

javascript angular-material angular

3
推荐指数
1
解决办法
3749
查看次数

dynamically split an array of objects into groups based on values of a property

I am trying to dynamically split an array of objects into groups based on values of a property.

Here is an example of the input:

`input = [
    {"name": "john", "location": "first"},
    {"name": "steve", "location": "first"},
    {"name": "paul", "location": "another"},
    {"name": "tony", "location": "random"},
    {"name": "ant", "location": "random"}
]`
Run Code Online (Sandbox Code Playgroud)

and the desired output:

`solution(input, location) = [
    first:   [{"name": "john", "location": "first"},
              {"name": "steve", "location": "first"}],
    another: [{"name": "paul", "location": "another"}],
    random:  [{"name": "tony", "location": "random"},
              {"name": "ant", "location": "random"}] …
Run Code Online (Sandbox Code Playgroud)

javascript typescript

1
推荐指数
1
解决办法
4831
查看次数

如果猫鼬命令 Model.insertMany 失败,是否会向数据库写入任何内容?

在 Model.insertMany 的文档中,它说当 options.ordered == true 时,该方法将在第一个错误时失败。

\n\n

https://mongoosejs.com/docs/api.html#model_Model.insertMany

\n\n
\n

[options.ordered \xc2\xabBoolean\xc2\xbb = true] 如果为 true,则在遇到第一个错误时快速失败。如果为 false,将插入它可以插入的所有文档并稍后报告错误。ordered = false 的 insertMany() 称为“无序”insertMany()。

\n
\n\n

可以:

\n\n
    \n
  • 出现错误并且没有向数据库写入任何文档。(我想要什么)
  • \n
\n\n

或者

\n\n
    \n
  • 写文件之前发生的错误,有错误,然后不再写文件?
  • \n
\n

mongoose mongodb node.js

1
推荐指数
1
解决办法
6677
查看次数