我有以下 View (interests.component.html):

<Tree #tree [nodes]="nodes" [options]="treeOptions">
  <template #treeNodeTemplate let-node>
    <inline-editor #nodeEdit type="text" [(ngModel)]="node.data.name" (onEdit)="beginEditable($event)" (onSave)="saveEditable($event)" name="node{{node.data.id}}" size="8"></inline-editor>

      <a (click)="addNode(node)"><i class="pull-right btn btn-xs icon-plus"></i></a>
      <a (click)="editNode(node)"><i class="pull-right btn btn-xs icon-note"></i></a>
      <a (click)="deleteNode(node)"><i class="pull-right btn btn-xs icon-trash"></i></a>
  </template>
</Tree>

我的组件看起来像这样(interests.component.ts):
import { Component, ViewChild, ViewChildren, QueryList } from '@angular/core';
import * as _ from "lodash";
import * as $ from "jquery";

import { AppState } from '../app.service';
import {TreeModule, TreeNode, TREE_ACTIONS, KEYS, IActionMapping } from 'angular2-tree-component';
import {InlineEditorComponent} from 'ng2-inline-editor';

@Component({
  selector: 'interests',
  providers: [],
  styleUrls: ['./interests.component.scss'],
  templateUrl: './interests.component.html'
})
export class Interests {
  @ViewChild('tree') tree: any;
  @ViewChildren('nodeEdit') nodeEdits: any;

  /** Level multiplikator for tree id creation. */
  public static readonly LEVEL_MULTIPLIKATOR = 100000;

  /** Last inline text element which is/was in edit mode. */
  public lastSelectedEditElement: any;

  /** Id of last selected edit node. */
  public lastSelectedEditId: number;

  /** Options for the tree component. */
  treeOptions = {
    allowDrag: true
  };

  /** contains the tree nodes. */
  nodes: any;

  ngAfterViewInit() {
    console.log(this.nodeEdits);
  }

}

我想在单击编辑时获取inline-editor来调用编辑功能,但无法获得对该对象的引用。
我尝试了以下viewChildren:
@ViewChildren('nodeEdit') nodeEdits: any;

但是它始终是不确定的。
要获得treetreeNodeTemplate,可以按预期工作。

希望有人能够帮助我:)

更新

我尝试在单击编辑按钮时访问this.nodeEdits,以便在此之前调用ngAfterViewInit()

我尝试从我的兴趣 Controller (即 View 的 Controller )访问它。

最佳答案

您无法在nodeEdits或构造函数中访问ngOnInit()。仅当调用ngAfterViewInit()时才设置this.nodeEdits

09-27 08:37