从组件发送服务作为@input

时间:2019-01-19 16:03:37

标签: angular angular-services angular-components

是否可以将从注入接收的服务发送到其他组件? 像这样:

TS定义

export class DealComponent implements OnInit {


    filters: Filter[] = [
        new Filter({type: 'text', label: 'text', range: false}),
        new Filter({type: 'number', label: 'number', range: true}),
        new Filter({type: 'select', label: 'select', range: false, dataProvider: this.templateService}),
        new Filter({type: 'date', label: 'date', range: true}),
        new Filter({type: 'date', label: 'date 2', range: false}),
    ];

    constructor(
        private dealService: DealService,
        public dialog: MatDialog,
        private router: Router,
        private activatedRoute: ActivatedRoute,
        private templateService: TemplateService
    ) {

    }
}

HTML交易模板比:

<app-filter [filters]="filters"></app-filter>

然后在FilterComponent

中使用

当前我收到错误

ERROR TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at JsonPipe.push../node_modules/@angular/common/fesm5/common.js.JsonPipe.transform (common.js:5085)
    at Object.updateRenderer (deal.component.html:30)
    at Object.debugUpdateRenderer [as updateRenderer] (core.js:20375)
    at checkAndUpdateView (core.js:19750)
    at callViewAction (core.js:19986)
    at execComponentViewsAction (core.js:19928)
    at checkAndUpdateView (core.js:19751)
    at callViewAction (core.js:19986)
    at execEmbeddedViewsAction (core.js:19949)

0 个答案:

没有答案