组件upperCaseComponent模板出错

Error occurs in the template of component upperCaseComponent

显示模板错误,

错误:

我的html

<input type="text" [(ngModel)]="mymessage"
<button (click)="clickMe()"> send</button>
<br><br>
<h1>{{result | json}}</h1>

我的component.ts

import {Component} from "@angular/core";
export class MyComponent {
private result: any;
constructor()
}

欢迎来到 SO。

关于您的问题,能否请您确认以下几点,以便我更好地帮助您。

  1. 能否在此处编辑问题和 post 组件代码。 (您可以在此处屏蔽敏感数据)。

  2. 请检查您使用的绑定数据是否标有private

所以这里的错误说它无法在 uppercase.component.ts

中找到变量 'mymessage'
export class UpperCaseComponent {
 public results: any; // Change it private to public
 public mymessage: any;
}

如果您尝试在模板中访问变量,您需要将其声明为 public,就像您将其声明为私有一样,它只能在 class

中访问

UpperCaseComponent.ts 的结果字段为 privateuppercase.component.html 无法访问它,因此将结果字段设置为 public。 至于 myMessage 字段,因为它没有在 UpperCaseComponent.ts 中的任何地方定义,我假设您想从父组件设置它,然后在 [=10] 中创建一个 @Input myMessage 字段=] 并在模板中使用它。在任何你想使用这个 UpperCaseComponent

的父组件中绑定它

这样试试:

export class upperCaseComponent {
  result: any;
  mymessage: String;

  ...  // other code goes here
}