我在Angular3 Dart项目中有了一条指令:
@Directive(
selector: "[sample]",
inputs: const ["text1", "text2"]
)
class SampleDirective implements AfterContentInit {
... more code ...
@Input("text1") String text1 = "Some Text 1";
@Input("text2") String text2 = "Some Text 2";
}
现在,当我使用此指令时:
<a-component *sample></a-component>
如何传递
text1
和text2
字段?骗子提到了以下示例:
<p *myUnless="myExpression">...</p>
,但未说明myExpression
部分的外观。这些是我已经尝试过的,但是都没有编译。
<a-component *sample="text1:'TESTING' "></a-component>
<a-component *sample="text1='TESTING' "></a-component>
<a-component *sample="{text1:'TESTING'}"></a-component>
<a-component *sample="{text1='TESTING'}"></a-component>
知道如何表达这些表达式吗?
最佳答案
@Input("sampleText1") String text1 = "Some Text 1";
要么
@Input() String sampleText1 = "Some Text 1";
与
<a-component *sample="text1:'TESTING' "></a-component>
要么
<template sample [sampleText1]="'TESTING'">
<a-component></a-component>
</template>
更新
必须有一个与指令选择器匹配的
@Input()
@Input()
String sample;
并且需要传递一个值
<a-component *sample="'someValueForSample' text1:'TESTING' "></a-component>
然后,可以添加其他输入的值分配。
关于angular - 用于将数据传递到Angular指令的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43979303/