1

I've got a directive in an Angular3 Dart project:

@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";

}

Now when I'm using this directive:

<a-component *sample></a-component>

How do I pass in the text1 and text2 fields?

The cheatsheat mentions this example: <p *myUnless="myExpression">...</p>, but doesn't state what the myExpression part should look like.

These are the ones I've already tried, but none of them compiles.

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

Any idea how these expressions should be structured?

1 Answer 1

4
@Input("sampleText1") String text1 = "Some Text 1";

or

@Input() String sampleText1 = "Some Text 1";

with

<a-component *sample="text1:'TESTING' "></a-component>

or

<template sample [sampleText1]="'TESTING'">
  <a-component></a-component>
</template>

update

There needs to be an @Input() that matches the selector of the directive

@Input() 
String sample;

and a value needs to be passed

<a-component *sample="'someValueForSample' text1:'TESTING' "></a-component>

then after that value assignments for other inputs can be added.

Sign up to request clarification or add additional context in comments.

3 Comments

<sample-form-3 *sample="text1:'TESTING' "></sample-form-3> gives me ParseErrorLevel.FATAL: Parser Error: Unexpected token :, expected identifier, keyword, or string at column 13 in [sample text1:'TESTING' ]
I'm quite sure I tested it. I'll have another look tomorrow.
I realized I was missing such a variable. Also, any secondary inputs needs to start with the same part as the directive, so text1:TESTING only sets if I have an input called sampleText1, otherwise it simply throws a FATAL exception. Very fincky to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.