【发布时间】:2020-10-17 20:20:13
【问题描述】:
我的应用中有一个这样的组件:
@Component({
selector: 'app-payment-intent',
templateUrl: './payment-intent.component.html',
styleUrls: ['./payment-intent.component.css']
})
export class PaymentIntentComponent implements OnInit {
static = false;
@ViewChild(StripeCardComponent, this.static) card: StripeCardComponent;
但是,当我尝试编译应用程序时,我得到了
Object is possibly 'undefined'
错误出现在变量static = false 中,导致@ViewChild(StripeCardComponent, this.static) card 尽可能接收变量undefined,但正如您所见,变量不是undefined,变量是在@ 中初始化的布尔值987654327@..
我能做些什么来解决这个问题?
谢谢!
【问题讨论】:
-
您可以尝试将其定义为
static: boolean = false;。但问题可能在于static是保留字,因此您可能需要重命名变量。
标签: angular typescript undefined