Angular 13传递参数OnClick,使用
我有一系列对象。我迭代的是,循环并将每个项目的名称传递给针对函数导航(url:string)的OnClick
。
{{{sousmenu.titre}}
compenent:
导航(url:string):void { this.router.navigate([url]); }
错误消息是: 类型'字符串的参数|未定义的“无法分配到类型“字符串”的参数。 类型“未定义”不能分配给'string'.ngtsc(2345)
I have an array of objects. i am iterating that in loop and passing each item's name to onclick which targets a function navigate(url:string) in cmpenent.ts
html :
{{sousMenu.titre}}
compenent:
navigate(url:string):void{
this.router.navigate( [url]); }
the error message is :
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.ngtsc(2345)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以提供一个完整的代码示例,以便我们可以在总上下文上提供建议。
有时,如果属性是用一种'字符串|的类型定义的当功能仅呼叫“字符串”时,需要未定义的“额外处理”。
您可以做的某些事情如下:
这可能不是最好的路线,但没有进一步查看代码,很难看到我们如何扩展它。
Can you provide a complete code example so we can advise on the total context.
Sometimes if a property is defined with a type of 'string | undefined' additional handling is needed when the function calls for only a 'string'.
Some of the things you can do are the following:
That might not be the best route but without further viewing of the code it's hard to see how we may expand on it.