如何在Aurelia HTML only元素中设置可绑定属性的默认值

如何在Aurelia HTML only元素中设置可绑定属性的默认值,第1张

概述假设我有以下html元素: <template bindable='value: Math.random()'> ${value}</template><!-- In another component {Main} --><template> <require from='./that-element'></require> <that-element></that 假设我有以下HTML元素:

<template bindable='value: Math.random()'>    ${value}</template><!-- In another component {Main} --><template>    <require from='./that-element'></require>    <that-element></that-element></template>

结果是主要组件中的空字符串.问题是如何为仅HTML元素定义默认值?

编辑:如果2个绑定需要具有相同的唯一默认值,则元素的默认值将不起作用.我可以让它自己独一无二,但我必须手动完成它.正在寻找类似Math.random()的东西

解决方法 < template>上的可绑定属性的内容标签处理为 comma-separated list of strings.因此,您将无法在那里设置默认值.

我可以想到两种方法:

>在父视图模型类中设置默认值并使用显式绑定.考虑到上述情况,这将适合您.

< that-element value.bind =“someVarFromParent”>< / that-element>

>在一些非常简单的情况下,当默认值应该是静态字符串时,您可以在插值中使用JavaScript表达式.

${value || ‘默认值’}

要点演示:https://gist.run/?id=f0698d5b0066c3674c29c40d850217dc

总结

以上是内存溢出为你收集整理的如何在Aurelia HTML only元素中设置可绑定属性的默认值全部内容,希望文章能够帮你解决如何在Aurelia HTML only元素中设置可绑定属性的默认值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1045837.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存