angular - 用于将数据传递到Angular指令的语法

标签 angular dart angular-dart

我在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>

如何传递text1text2字段?

骗子提到了以下示例:<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/

相关文章:

angular - ngrx/effects 中的 if/else 怎么办?

angular - 将本地JSON文件映射为键值对数组

c# - 如何在 .Net Core 中创建自定义异常和错误处理程序?

dart - 为什么 toList() 在 Dart 中创建一个 List<dynamic> ?

dart - 无法加载内核二进制文件 (Dart SDK dev.69.4)

dart - 在 Angular Dart 中创建重定向

angular - 我如何处理 RxJS 中相互传递数据的子顺序 URL 调用?

dart - 在 Dart 中读取文件

node.js - flutter 如何在http.get请求中传递变量

attributes - NgOneWay和NgAttr-有什么区别?