0

我有以下代码:

  private loadSlides(): Promise<any> {
    return new Promise((resolve, reject) => {
      const component = builder.parse(slideTemplate);
      component.bindingContext = {
        content: 'HHAHAAHA'
      };
      resolve(component);
    });
  }

这是 slideTemplate 的值:

export const slideTemplate: string = `
  <GridLayout row="0" rows="*, 2*, *">
      <GridLayout width="57%" row="0" horizontalAlignment="center" verticalAlignment="center">
          <Label class="lobster-regular carousel-item-head" [text]="content" textWrap="true"></Label>
      </GridLayout>
  </GridLayout>
`;

现在,当我从模板绑定值时,它只显示空字符串。

为什么呢?

4

1 回答 1

0

您不能使用 Angular 模板/绑定语法builder.parse(...),它是在 Angular 上下文之外创建的。

由于您使用bindingContext的是处理数据绑定的 NativeScript Core 方式,因此您应该使用text="{{ content }}"

export const slideTemplate: string = `
  <GridLayout row="0" rows="*, 2*, *">
      <GridLayout width="57%" row="0" horizontalAlignment="center" verticalAlignment="center">
          <Label class="lobster-regular carousel-item-head" text="{{ content }}" textWrap="true"></Label>
      </GridLayout>
  </GridLayout>
`;

我不确定你为什么在这里需要构建器,如果可能的话,我建议你坚持使用 Angular 组件。

于 2019-06-10T12:14:36.147 回答